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.2.0.tar.gz
(20.0 kB
view details)
Built Distribution
File details
Details for the file aiooss2-0.2.0.tar.gz
.
File metadata
- Download URL: aiooss2-0.2.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 553bb9c78af0efcc5e2925a49f7b220c683f7d4ce6f9ac942b5c4bcd8d5c6ec8 |
|
MD5 | 2c5956137d00d2dc2509191da1944854 |
|
BLAKE2b-256 | cfe2a3a028ff3ac4a48b7bad3ac920586f49698200ba4774671d98527f56da23 |
Provenance
File details
Details for the file aiooss2-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: aiooss2-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 16.0 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 | a919503b07497b443c58fdb6545e25ae2accb6ffe37cadcf185335bfa95e14d1 |
|
MD5 | 34ad62c9dfdb0d74a3f90194601a2531 |
|
BLAKE2b-256 | 546acb5d939132600c287337598462c194df88e5d6df18ceed623b351a13dcc3 |