Async client for aliyun OSS
Project description
aiooss22
Async client for aliyun OSS(Object Storage Service) using oss2 and aiohttp_/asyncio_.
The main purpose of this library is to support aliyun OSS async api, but other services should work (but maybe with minor fixes). For now, we have tested only upload/download/delete/list api for OSS. More functionality will be coming soon.
Install
pip install aiooss22
Basic Example
import asyncio
import os
from aiooss22 import AioBucket, AioObjectIterator, Auth
OSS_ACCESS_KEY_ID = os.environ.get('OSS_ACCESS_KEY_ID')
OSS_SECRET_ACCESS_KEY = os.environ.get('OSS_SECRET_ACCESS_KEY')
BUCKET_NAME = os.environ.get("OSS_TEST_BUCKET_NAME")
async def async_go():
"""
example coroutine
"""
obj_name = "your_obj"
folder = "readme"
data_obj = f"{folder}/{obj_name}"
auth = Auth(OSS_ACCESS_KEY_ID, OSS_SECRET_ACCESS_KEY)
async with AioBucket(auth, "http://oss-cn-hangzhou.aliyuncs.com", BUCKET_NAME) as bucket:
# upload object to oss
data = b"\x01" * 1024
resp = await bucket.put_object(data_obj, data)
# download object to oss
async with await bucket.get_object(data_obj) as resp:
assert await resp.read() == data
# list oss objects
print(f"objects in {folder}")
async for obj in AioObjectIterator(
bucket, prefix=folder
): # pylint: disable=not-an-iterable
print(obj.key)
# delete object
resp = await bucket.delete_object(data_obj)
print(f"objects in {folder}, after delete")
async for obj in AioObjectIterator(
bucket, prefix=folder
): # pylint: disable=not-an-iterable
print(obj.key)
asyncio.run(async_go())
Run Tests
Make sure you have development requirements installed and your oss key and secret accessible via environment variables:
$pip3 install -e "."
$export OSS_ACCESS_KEY_ID=xxx
$export OSS_SECRET_ACCESS_KEY=xxx
Execute tests suite:
$pytest tests
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
aiooss2-0.1.5.tar.gz
(16.3 kB
view details)
Built Distribution
File details
Details for the file aiooss2-0.1.5.tar.gz
.
File metadata
- Download URL: aiooss2-0.1.5.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c335f12f9d435ca5c588408f72b16288d78b4fd912d1dd628c2a40ced322aede |
|
MD5 | 4cf17d4034a7190eaa67ff4c306056ad |
|
BLAKE2b-256 | 62c03759a1b706387bb89be0dfa338743dbd92c906d79dc74de653af1fa142e2 |
Provenance
File details
Details for the file aiooss2-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: aiooss2-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e66ee72c8b83e339060543e752d6d3f8eb2e7706efa68eac3031590e53f518a1 |
|
MD5 | a6039ada88217f1cc38b152933bc4db3 |
|
BLAKE2b-256 | 906ee8e7480d3c931013e2bca6d1086fd90dad2f0e59e787b5c7b1223c8ca4df |