Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s3_url_helper-0.4.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

s3_url_helper-0.4.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file s3_url_helper-0.4.2.tar.gz.

File metadata

  • Download URL: s3_url_helper-0.4.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for s3_url_helper-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6499e04afbe51b7ab07dcb69fe7dd1c9b627a1510bacd3d20fd50e48f047fdf3
MD5 6de69058f2637c7350daac5e69921907
BLAKE2b-256 693f550020f0ffa9e16d21c2f48226dd8f422377ba63d6e7dc6cc308103593b0

See more details on using hashes here.

File details

Details for the file s3_url_helper-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for s3_url_helper-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a28d5f8d9a6a2ed5223c7ce917b26b52835aee1c7bb91c240145edbd8842f9fa
MD5 a19591d009cf3ec43865aecb163ff1b4
BLAKE2b-256 74d2083ad165413a539fedee5adbddd1cd86f3550e2618528b572bbad5a6e9fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page