Asyncio compatible SDK for Yandex Object Storage
Project description
Yandex-S3
Asyncio compatible SDK for Yandex Object Storage inspired by aioaws.
This library does not depend on boto, boto3 or any of the other bloated, opaque and mind thumbing AWS SDKs. Instead, it is written from scratch to provide clean, secure and easily debuggable access to AWS services I want to use.
It currently supports:
- S3 - list, delete, recursive delete, generating signed upload URLs, generating signed download URLs
- AWS Signature Version 4
authentication for any AWS service (this is the only clean & modern implementation of AWS4 I know of in python, see
core.py
)
The only dependencies of yandex-s3, are:
- aiofiles - for asynchronous reading of files
- cryptography - for verifying SNS signatures
- httpx - for HTTP requests
- pydantic - for validating responses
Install
pip install yandex-s3
S3 Usage
import asyncio
# requires `pip install yandex-s3`
from s3 import S3Client
# requires `pip install devtools`
from devtools import debug
async def s3_demo():
s3 = S3Client(
access_key='<access key>',
secret_key='<secret key>',
region='<region>',
s3_bucket='test-bucket'
)
# upload a file:
await s3.upload('dir/subdir/dummy.txt', b'Dummy')
# list all files in a bucket
files = [f async for f in s3.list()]
debug(files)
"""
[
S3File(
key='dir/subdir/dummy.txt',
last_modified=datetime.datetime(...),
size=5,
e_tag='...',
storage_class='STANDARD',
),
] (list) len=1
"""
# list all files with a given prefix in a bucket
files = [f async for f in s3.list('dir/subdir/')]
debug(files)
# # delete a file
# await s3.delete('dir/subdir/dummy.txt')
# # delete two files
# await s3.delete('dir/subdir/file1.txt', 'dir/subdir/file2.txt')
# delete recursively based on a prefix
await s3.delete_recursive('dir/subdir')
# generate an upload link suitable for sending to a borwser to enabled
# secure direct file upload (see below)
upload_data = s3.signed_upload_url(
path='dir/subdir',
filename='dummy.txt',
content_type='text/plain',
size=123,
)
debug(upload_data)
"""
{
'url': 'https://test-bucket.storage.yandexcloud.net/',
'fields': {
'Key': 'dir/subdir/dummy.txt',
'Content-Type': 'text/plain',
'AWSAccessKeyId': '...',
'Content-Disposition': 'attachment; filename="dummy.txt"',
'Policy': ('...'),
'Signature': '...',
},
} (dict) len=2
"""
# generate a temporary link to allow yourself or a client to download a file
download_url = s3.signed_download_url('dir/subdir/dummy.txt', max_age=60)
print(download_url)
#> https://test-bucket.storage.yandexcloud.net/dir/subdir/dummy.txt?AWSAccessKeyId=...&Signature=...&Expires=...
# download file
content = await s3.download('dir/subdir/dummy.txt')
print(content)
#> b'Dummy'
async def main():
await s3_demo()
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yandex-s3-0.1.1.tar.gz
(11.6 kB
view details)
Built Distribution
yandex_s3-0.1.1-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file yandex-s3-0.1.1.tar.gz
.
File metadata
- Download URL: yandex-s3-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e0ae19c61a0fde40d9b7487812e4328fe28ee92ac97014c09678007872e8feb |
|
MD5 | 3b45797e462770c2c8b2249fc241d02e |
|
BLAKE2b-256 | 78eaf1b5b6d9bb01e6874ad22db2b0017759865deb0ed6f4db8266bb73ac7454 |
File details
Details for the file yandex_s3-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: yandex_s3-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf4ca5f20a68b16eea7c346a244c4eff1ec18e8951b632147efd9348eba33ce |
|
MD5 | f319e2e02c60ce2895f430a0e3c30a2e |
|
BLAKE2b-256 | 95c1f0e15d0dc3891284bcdcc3cd2150114b6816dcc3629a3e9188da0a75217c |