Skip to main content

Async DynamoDB table helper based on aioboto3.

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:

  • uvloop 0.19.0
  • aioboto3 13.0.0
  • aiobotocore 2.13.0
  • aiodynamo 24.7
  • aiohttp 3.9.5
  • boto3 1.34.106
  • httpx 0.28.1
Test Avg latency 1 Avg latency 2 CPU time 1 CPU time 2
aioboto3 (client) 3.12ms 2.67ms 0.75ms 0.71ms
aioboto3 (resource) 3.39ms 2.64ms 0.80ms 0.78ms
aspen-dynamo 2.61ms 3.24ms 0.78ms 0.79ms
raw request (aiohttp) 2.43ms 2.17ms 0.26ms 0.28ms
aiodynamo (aiohttp) 2.34ms 2.15ms 0.32ms 0.32ms
raw request (httpx) 2.53ms 2.54ms 2.05ms 1.99ms
aiodynamo (httpx) 3.02ms 3.01ms 2.07ms 2.23ms

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

aspen_dynamo-0.1.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aspen_dynamo-0.1.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file aspen_dynamo-0.1.2.tar.gz.

File metadata

  • Download URL: aspen_dynamo-0.1.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for aspen_dynamo-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4a943cd453e8aff6591f7f36297e9e62f10396e640cadc7fadf09dbc7c1b54ba
MD5 d2324a8575fef11f7f47aeac1054a256
BLAKE2b-256 3e3313c98bd033e43490a5939bc1d01b21944bc3fc148cc90ad09621c5d4eebb

See more details on using hashes here.

File details

Details for the file aspen_dynamo-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aspen_dynamo-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for aspen_dynamo-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0e723c097e381dd20989a36013ea6d352919c6c9afebad65c85abc66065b000
MD5 75ba001e7b7df950111112cb9d459bb6
BLAKE2b-256 2c5ff2e81f4eaba1787999ee9c19e09b868702e4ed5c6285b57208efcc519750

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page