Giter Club home page Giter Club logo

s3-url-helper's Introduction

Coverage Badge

Overview

S3Url is a helper class that can help with simple operations on AWS S3 objects.

Installation

Get from https://pypi.org/project/s3-url-helper/
e.g pip install s3-url-helper

Usage

from s3_url import S3Url

file_url = S3Url(f's3://test-bucket/prefix/file.json')

# url component properties
assert file_url.bucket == 'test-bucket'
assert file_url.key == 'prefix/file.json'

# factory methods
file_url = S3Url.from_url('s3://test-bucket/prefix/file.json')
file_url = S3Url.from_bucket_key(bucket='test-bucket', key='prefix/file.json')

# access underlying boto3 s3 resource object
boto3_obj = file_url.object

# return url string
url_str: str = file_url.url
url_str: str = str(file_url)
assert url_str == 's3://test-bucket/prefix/file.json'

# check if file exists
exists: bool = file_url.exists()
assert exists

# check if any files exist in prefix (url should end with /)
prefix_exists = S3Url('s3://test-bucket/prefix/').prefix_exists()
assert prefix_exists

# read text/json
file_content: str = file_url.read_text()
file_content_json: json = file_url.read_json()

# delete file
file_url.delete()
assert not file_url.exists()

# write text/json
file_url.write_text("test data")
file_url.write_json({"testEntry": "test data"})
assert file_url.exists()

# copy to another object
file_url.copy_to('s3://test-bucket/prefix/file-copy.json')
S3Url('s3://test-bucket/prefix/another-file-copy.json').copy_from(file_url)

# delete all filed in prefix
prefix_url = S3Url('s3://test-bucket/prefix/')
prefix_url.delete_dir()

assert not prefix_url.prefix_exists()
assert not file_url.exists()

# see tests for more examples

Development notes

Install dev dependencies: pip install '.[dev]' pip install '.[build]'

build/upload:

py -m build
py -m twine upload --repository pypi dist/*  

todo - write docstrings

s3-url-helper's People

Contributors

n-orlov avatar

Stargazers

Elliot Ford avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.