Skip to main content

Async AWS SDK for Python

https://img.shields.io/pypi/v/aioboto3.svg https://github.com/terrycain/aioboto3/actions/workflows/CI.yml/badge.svg Documentation Status Updates

Breaking changes for v9, aioboto3.resource and aioboto3.client methods no longer exist, make a session then call session.client etc… This was done for various reasons but mainly that it prevents the default session living longer than it should as that breaks situations where eventloops are replaced.

The .client and .resource functions must now be used as async context managers.

Now that aiobotocore has reached version 1.0.1, a side effect of the work put in to fix various issues like bucket region redirection and supporting web assume role type credentials, the client must now be instantiated using a context manager, which by extension applies to the resource creator. You used to get away with calling res = aioboto3.resource('dynamodb') but that no longer works. If you really want to do that, you can do res = await aioboto3.resource('dynamodb').__aenter__() but you’ll need to remember to call __aexit__.

There will most likely be some parts that dont work now which I’ve missed, just make an issue and we’ll get them resoved quickly.

Creating service resources must also be async now, e.g.

async def main():
    session = aioboto3.Session()
    async with session.resource("s3") as s3:
        bucket = await s3.Bucket('mybucket')  # <----------------
        async for s3_object in bucket.objects.all():
            print(s3_object)

Updating to aiobotocore 1.0.1 also brings with it support for running inside EKS as well as asyncifying get_presigned_url


This package is mostly just a wrapper combining the great work of boto3 and aiobotocore.

aiobotocore allows you to use near enough all of the boto3 client commands in an async manner just by prefixing the command with await.

With aioboto3 you can now use the higher level APIs provided by boto3 in an asynchronous manner. Mainly I developed this as I wanted to use the boto3 dynamodb Table object in some async microservices.

While all resources in boto3 should work I havent tested them all, so if what your after is not in the table below then try it out, if it works drop me an issue with a simple test case and I’ll add it to the table.

Services

Status

DynamoDB Service Resource

Tested and working

DynamoDB Table

Tested and working

S3

Working

Kinesis

Working

SSM Parameter Store

Working

Athena

Working

Example

Simple example of using aioboto3 to put items into a dynamodb table

import asyncio
import aioboto3
from boto3.dynamodb.conditions import Key


async def main():
    session = aioboto3.Session()
    async with session.resource('dynamodb', region_name='eu-central-1') as dynamo_resource:
        table = await dynamo_resource.Table('test_table')

        await table.put_item(
            Item={'pk': 'test1', 'col1': 'some_data'}
        )

        result = await table.query(
            KeyConditionExpression=Key('pk').eq('test1')
        )

        # Example batch write
        more_items = [{'pk': 't2', 'col1': 'c1'}, \
                      {'pk': 't3', 'col1': 'c3'}]
        async with table.batch_writer() as batch:
            for item_ in more_items:
                await batch.put_item(Item=item_)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

# Outputs:
#  [{'col1': 'some_data', 'pk': 'test1'}]

Things that either dont work or have been patched

As this library literally wraps boto3, its inevitable that some things won’t magically be async.

Fixed:

  • s3_client.download_file* This is performed by the s3transfer module. – Patched with get_object

  • s3_client.upload_file* This is performed by the s3transfer module. – Patched with custom multipart upload

  • s3_client.copy This is performed by the s3transfer module. – Patched to use get_object -> upload_fileobject

  • dynamodb_resource.Table.batch_writer This now returns an async context manager which performs the same function

  • Resource waiters - You can now await waiters which are part of resource objects, not just client waiters, e.g. await dynamodbtable.wait_until_exists()

  • Resource object properties are normally autoloaded, now they are all co-routines and the metadata they come from will be loaded on first await and then cached thereafter.

  • S3 Bucket.objects object now works and has been asyncified. Examples here - https://aioboto3.readthedocs.io/en/latest/usage.html#s3-resource-objects

Amazon S3 Client-Side Encryption

Boto3 doesn’t support AWS client-side encryption so until they do I’ve added basic support for it. Docs here CSE

CSE requires the python cryptography library so if you do pip install aioboto3[s3cse] that’ll also include cryptography.

This library currently supports client-side encryption using KMS-Managed master keys performing envelope encryption using either AES/CBC/PKCS5Padding or preferably AES/GCM/NoPadding. The files generated are compatible with the Java Encryption SDK so I will assume they are compatible with the Ruby, PHP, Go and C++ libraries as well.

Non-KMS managed keys are not yet supported but if you have use of that, raise an issue and i’ll look into it.

Documentation

Docs are here - https://aioboto3.readthedocs.io/en/latest/

Examples here - https://aioboto3.readthedocs.io/en/latest/usage.html

Features

  • Closely mimics the usage of boto3.

Todo

  • More examples

  • Set up docs

  • Look into monkey-patching the aws xray sdk to be more async if it needs to be.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template. It also makes use of the aiobotocore and boto3 libraries. All the credit goes to them, this is mainly a wrapper with some examples.

Release files for aioboto3 9.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioboto3 9.6.0
File Size Uploaded
aioboto3-9.6.0.tar.gz 30.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aioboto3 9.6.0
File Interpreter ABI Platform
aioboto3-9.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.1 kB

Release files / aioboto3-9.6.0.tar.gz

Download URL aioboto3-9.6.0.tar.gz
Size 30.9 kB
Tags Source
SHA-256 checksum
How to use checksums
abac5dcfa871627b7040e6586a69e3359e2dfc4e15dc66135969f2d26fbdcb3b
BLAKE2b-256 checksum
How to use checksums
8be37a500d59808725fd2a9614bb29f14a84ec00f93e0d9f1bf59006f29ec1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.13.0-1022-azure

Release files / aioboto3-9.6.0-py3-none-any.whl

Download URL aioboto3-9.6.0-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a62de3203c7372b5f1247057b9705eeb26c45ee65b5d1fab91767e4f31fd7b47
BLAKE2b-256 checksum
How to use checksums
8ab78be5d86ac9404b3231a53d965b49d843c1cd4fe9afdc459915cb45cea107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.13.0-1022-azure

Release history Release notifications | RSS feed

15.5.0

2 release files

15.4.0

2 release files

15.3.0

2 release files

15.1.0

2 release files

15.0.0

2 release files

14.0.0

2 release files

13.4.0

2 release files

13.3.0

2 release files

13.2.0

2 release files

13.1.0

2 release files

13.0.0

2 release files

12.4.0

2 release files

12.2.0

2 release files

12.0.0

2 release files

11.3.1

2 release files

11.3.0

2 release files

11.2.0

2 release files

11.1.1

2 release files

11.1.0

2 release files

10.4.0

2 release files

10.1.0

2 release files

10.0.0

2 release files

This release

9.6.0 This release

2 release files

9.5.0

2 release files

9.4.0

2 release files

9.3.1

2 release files

9.3.0

2 release files

9.2.2

2 release files

9.2.0

2 release files

9.1.0

2 release files

9.0.0

1 release file

8.3.0

1 release file

8.2.1

1 release file

8.2.0

2 release files

8.1.1

2 release files

8.1.0

2 release files

8.0.5

2 release files

8.0.4

2 release files

8.0.3

2 release files

8.0.2

2 release files

8.0.1

2 release files

8.0.0

2 release files

7.1.0

2 release files

7.0.0

2 release files

6.5.0

2 release files

6.4.1

2 release files

6.3.0

2 release files

6.2.2

2 release files

6.2.1

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.1.2

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.0.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page