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

Uploaded Source

Built Distribution

aiooss2-0.2.3-py2.py3-none-any.whl (20.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for aiooss2-0.2.3.tar.gz
Algorithm Hash digest
SHA256 735d7f0f4ca22533e954c21fe286870317128bb87b339037d7f1b1e9fa505fae
MD5 607017f5e079fce3a934cbb076b6fb57
BLAKE2b-256 0c2855463697cacc9a66c00c43e2e5d28ff0ad39339ae3975617db60f85e390a

See more details on using hashes here.

Provenance

File details

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

File metadata

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

File hashes

Hashes for aiooss2-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 258a1eda1ff220177bac791bf465475e43eed171831c9d46a4e88a776ba67f30
MD5 c8f21bd7375a2101347e2713efff8ce5
BLAKE2b-256 b83062894a1917bf21d18c2d082d040fdb710f756c335e1408a7a9f0012d51a9

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