Async DynamoDB table helper.
Project description
aspen-dynamo
Async DynamoDB table helper built on aioboto3. It wraps a DynamoDB table
resource with small conveniences for key handling, pagination, and optional
Pydantic model validation.
Installation
pip install aspen-dynamo
Optional extras:
pip install "aspen-dynamo[benchmark]"
Usage
Create a DynamoDBTable with a boto3 DynamoDB resource:
import aioboto3
from aspen_dynamo import DynamoDBTable
session = aioboto3.Session()
async with session.resource("dynamodb") as resource:
table = DynamoDBTable("MyTable", "pk", resource=resource)
item = await table.get_item(123)
print(item)
Partition + sort key (composite key)
Pass a tuple of attribute names for a table with a partition key and sort key:
import aioboto3
from aspen_dynamo import DynamoDBTable
session = aioboto3.Session()
async with session.resource("dynamodb") as resource:
table = DynamoDBTable("MyTable", ("pk", "sk"), resource=resource)
item = await table.get_item(123, "v1")
print(item)
Usage with a Pydantic model
Provide a model to coerce DynamoDB items into typed objects:
import aioboto3
from pydantic import BaseModel
from aspen_dynamo import DynamoDBTable
class Widget(BaseModel):
pk: int
name: str
session = aioboto3.Session()
async with session.resource("dynamodb") as resource:
table = DynamoDBTable("MyTable", "pk", resource=resource, model=Widget)
widget = await table.get_item(123)
print(widget.name)
Benchmark
The benchmark.py script compares aspen-dynamo to other async DynamoDB
clients. It uses the same DynamoDBTable API as above:
python -m aspen_dynamo.benchmark MyTable pk 123
Results from two runs:
uvloop0.19.0aioboto313.0.0aiobotocore2.13.0aiodynamo24.7aiohttp3.9.5boto31.34.106httpx0.28.1
| Test | Avg latency 1 | Avg latency 2 | CPU time 1 | CPU time 2 |
|---|---|---|---|---|
| aspen-dynamo | 3.24ms | 2.61ms | 0.78ms | 0.79ms |
| boto3 (client) | 2.67ms | 3.12ms | 0.75ms | 0.71ms |
| boto3 (resource) | 2.64ms | 3.39ms | 0.80ms | 0.78ms |
| raw request (httpx) | 2.54ms | 2.53ms | 2.05ms | 1.99ms |
| aiodynamo (httpx) | 3.01ms | 3.02ms | 2.07ms | 2.23ms |
| raw request (aiohttp) | 2.17ms | 2.43ms | 0.26ms | 0.28ms |
| aiodynamo (aiohttp) | 2.15ms | 2.34ms | 0.32ms | 0.32ms |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aspen_dynamo-0.0.3.tar.gz.
File metadata
- Download URL: aspen_dynamo-0.0.3.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6e4541e61445a0abe6deee634a4ea59fb267587d488acece20cdeeedf07d1ad
|
|
| MD5 |
7aec6304bd4596d1fd9b6a2c07bc8f74
|
|
| BLAKE2b-256 |
c8f71f2ff52c8b4b82ccdf82a7d2d03b1f9fb3a198c2494bfa71973ddddeabb7
|
File details
Details for the file aspen_dynamo-0.0.3-py3-none-any.whl.
File metadata
- Download URL: aspen_dynamo-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0db84aae2f06e703c34d206bdda81823ca5da7ba6969a09d9fed37a82a36026b
|
|
| MD5 |
6d7cbf7164e6083065c7a0b1a9bc9abc
|
|
| BLAKE2b-256 |
1a5f2ce7a858fe297ea340da1bd52df880069721432ac06307b2f830d587a1bf
|