S3Url is a helper class that can help with simple operations on AWS S3 objects
Project description
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file s3_url_helper-0.5.0.tar.gz.
File metadata
- Download URL: s3_url_helper-0.5.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e826b34915910ae2e947d0df12dd1f403f35c0515a8aeb97d6dbafc4a8f9ccc9
|
|
| MD5 |
3dbb3817a48a279744891c5fcd70187c
|
|
| BLAKE2b-256 |
5b9778a1927129cd94244b14a97fc927a1293952ff13711679a647564eb724b3
|
File details
Details for the file s3_url_helper-0.5.0-py3-none-any.whl.
File metadata
- Download URL: s3_url_helper-0.5.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f3223291486b7629fd64f97b777f3e8d929b563dcc4d945b07c4ba243228631
|
|
| MD5 |
068a2691a240e09f88be1d9e5a2b3d10
|
|
| BLAKE2b-256 |
06e02b52465b834149a13c0bf4f8c118a0b8bf82b74af253ac821500b79483c9
|