Skip to main content

Async client for aliyun OSS

Project description

aiooss2

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


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.2.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

aiooss2-0.2.2-py2.py3-none-any.whl (20.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aiooss2-0.2.2.tar.gz.

File metadata

  • Download URL: aiooss2-0.2.2.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for aiooss2-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6c27fc949919efda163ce914a3485d9e0ca23a0bf62dcfab349de94574011232
MD5 1bd9ac4f6997ccd61c0cc9896181a518
BLAKE2b-256 80f36a25b922b9bc178af6aafa664f8e0fa542baa43ca8c3e84e25f1ad4daf73

See more details on using hashes here.

Provenance

File details

Details for the file aiooss2-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: aiooss2-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for aiooss2-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3d4d295d168f4098a57058f94315119ba4c4a1ee73975c1da9efadeb460d8cbc
MD5 c9df83636e89c2f461f1c6ff7cc61dd3
BLAKE2b-256 b2d4d34b9cbb595ce4d1584d30aa9d3ed7b14e39c88bafbd4f8b38b104485674

See more details on using hashes here.

Provenance

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