aiodynamo: Asyncio DynamoDB Client

raw JSON →
24.7 verified Tue Apr 14 auth: no python

aiodynamo is an asynchronous Python client for Amazon DynamoDB, built using asyncio. It provides a clean, Pythonic API for interacting with DynamoDB, including support for expressions, transactions, and various credential providers. The current version is 24.7, and releases occur somewhat irregularly, often monthly or quarterly, incorporating bug fixes and new features.

pip install aiodynamo
error ModuleNotFoundError: No module named 'aiodynamo'
cause This error occurs when the 'aiodynamo' package is not installed in your Python environment.
fix
Install the 'aiodynamo' package using pip: 'pip install aiodynamo'.
error ImportError: cannot import name 'Client' from 'aiodynamo'
cause This error occurs when attempting to import 'Client' from 'aiodynamo' without specifying the correct submodule.
fix
Import 'Client' from the 'aiodynamo.client' submodule: 'from aiodynamo.client import Client'.
error TypeError: 'NoneType' object is not callable
cause This error occurs when the HTTP client adapter is not properly initialized or passed as 'None' to the 'Client' constructor.
fix
Ensure that a valid HTTP client adapter is passed to the 'Client' constructor, such as 'AIOHTTP' or 'HTTPX'.
error AttributeError: module 'aiodynamo' has no attribute 'Table'
cause This error occurs when trying to access the 'Table' attribute directly from the 'aiodynamo' module, which does not exist.
fix
Use the 'table' method of the 'Client' instance to access a table: 'table = client.table("my-table")'.
error asyncio.exceptions.TimeoutError
cause This error occurs when an operation exceeds the allowed time limit, often due to network issues or unresponsive DynamoDB service.
fix
Increase the timeout settings in your HTTP client adapter or handle the timeout exception appropriately in your code.
breaking Support for Python 3.7 was dropped in version 23.10.
fix Upgrade to Python 3.8 or newer to use aiodynamo versions 23.10 and above.
gotcha aiodynamo requires an HTTP client library (like httpx or aiohttp) to be installed separately. The base `pip install aiodynamo` does not include one.
fix Install with an extra, e.g., `pip install aiodynamo[httpx]` or `pip install aiodynamo[aiohttp]`.
gotcha Version 23.10 introduced a timing issue with refreshable credentials that was fixed in 23.10.1. Older versions might exhibit unstable credential refreshing.
fix Ensure you are using `aiodynamo` version 23.10.1 or newer if relying on refreshable credentials.
gotcha Logging for requests and responses was separated into distinct named loggers in version 24.7.
fix Review and update your logging configuration if you were previously capturing all aiodynamo logs under a single logger and need specific request/response log handling.
gotcha Versions 21.9 and newer require `httpx>=0.15.0` when using the httpx client backend.
fix Ensure your `httpx` installation is at least version 0.15.0 or newer if you encounter dependency conflicts or unexpected behavior with older `httpx` versions.
pip install aiodynamo[httpx]
pip install aiodynamo[aiohttp]

This quickstart demonstrates how to initialize the aiodynamo client using environment variables for AWS credentials and region, and then perform a simple operation like listing tables. Remember to install an HTTP client like `httpx` (e.g., `pip install aiodynamo[httpx]`) for the client to function.

import asyncio
import os
from aiodynamo import Client, AWSCredentials

async def main():
    # Configure AWS credentials and region via environment variables
    # or replace with your actual values.
    # AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
    client = Client(
        region=os.environ.get("AWS_REGION", "us-east-1"),
        credentials=AWSCredentials(
            aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", ""),
            aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", ""),
        )
    )
    
    print("Attempting to connect to DynamoDB...")
    try:
        # Example: List tables (requires appropriate IAM permissions)
        response = await client.list_tables()
        print(f"DynamoDB Tables: {response.table_names}")
    except Exception as e:
        print(f"Error interacting with DynamoDB: {e}")
    finally:
        await client.close()
        print("Client closed.")

if __name__ == "__main__":
    asyncio.run(main())