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

Uploaded Source

Built Distribution

aiooss2-0.2.1-py2.py3-none-any.whl (18.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: aiooss2-0.2.1.tar.gz
  • Upload date:
  • Size: 22.6 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.1.tar.gz
Algorithm Hash digest
SHA256 34a9eb3253581470366b6d6d8b59ab993baad9a73c8b5bd13b9a35fb3d12ab33
MD5 4943d6ee25430e49a57a75cb879a87e0
BLAKE2b-256 090f4b9605db2580ce28b6dd2498fdd5328ab7baa1a7cb3d5e12acddc5e112b1

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aiooss2-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.8 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.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd319a2dfe07ea951bda2bc04162cbcb96e085d27ad51292c9c36f79dd3b5305
MD5 d61e04d4a9bae1eda8669e546d66735d
BLAKE2b-256 c8fce058d84a840f9b705e7c68c08185ae46ede52ded7121e94b2c3be1a5762c

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