Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pynamo

pynamo is a toolkit for building event-driven, serverless applications on DynamoDB and AWS AppSync with pydantic. You describe your data once, as pydantic models, and pynamo uses those same models at every stage of a change's life:

  1. Stored: pynamo.models reads and writes the models in a DynamoDB table, building every key from the model's own attributes.
  2. Served: pynamo.api publishes functions that take and return the models as an AppSync GraphQL API, generating the schema from their type hints.
  3. Reacted to: pynamo.streams hands every change to an item back to your code as a before and after pair of models, so work can follow on from a write without the writer knowing about it.

A change moves through an application like a tide. It comes in through the API, is written to the table, and then flows back out through the stream to whatever reacts to it:

client ── GraphQL ──▶ AppSync ──▶ Lambda: pynamo.api ──▶ DynamoDB: pynamo.models
                                                              │
                                                         item change
                                                              ▼
                       Lambda: pynamo.streams ◀───────── Kinesis data stream

At every step the data is validated as the same pydantic class, so a field added to a model is stored, published in the schema and delivered to stream handlers without being declared anywhere else.

Installation

pynamo needs Python 3.14 or later.

pip install aws-pynamo

pynamo.api also needs graphql-core, which the graphql extra installs:

pip install "aws-pynamo[graphql]"

A model's life

One model, served through the API and reacted to when it changes:

import logging

import boto3

from pynamo.api import Router
from pynamo.models import DynamoModel, single_table_indexes
from pynamo.streams import DynamoStreamHandler

DynamoModel.default_table(boto3.resource("dynamodb").Table("app"))


# Stored: keys are built from the model's attributes
class User(DynamoModel):
    """A user of the app."""

    user_id: str
    name: str

    class Meta:
        indexes = single_table_indexes(base=("USER#{user_id}", "USER"))


# Served: the schema is generated from the resolvers' signatures
router = Router()


@router.query()
def get_user(user_id: str) -> User:
    """Get a user by ID."""
    return User.get({"user_id": user_id})


@router.mutation()
def rename_user(user_id: str, name: str) -> User:
    """Change a user's name."""
    return User.update({"user_id": user_id}, {"name": name})


# Reacted to: each change arrives as the item before and after it
stream = DynamoStreamHandler()


@stream.handle(User, events=["MODIFY"])
def on_user_changed(old: User | None, new: User | None) -> None:
    """Record renames once they've been written."""
    if old is not None and new is not None and old.name != new.name:
        logging.info("User %s renamed from %s to %s", new.user_id, old.name, new.name)


# Each function is deployed as its own Lambda
def api_handler(event, context):
    return router(event, context)


def stream_handler(event, context):
    return stream.lambda_handler(event, context)

rename_user doesn't know that anything is listening, and on_user_changed doesn't know where the change came from. A rename made by an admin script, a migration or another service reaches the same handler.

Using the parts on their own

The three subpackages share models but don't depend on each other:

  • pynamo.models is a complete DynamoDB ORM without the API or streams.
  • pynamo.api serves any pydantic model, not just DynamoModels, so it can front data stored elsewhere.
  • pynamo.streams validates change images as any pydantic model, so it can consume changes from a table written by other code.

pynamo.types holds common field types, such as UTC datetimes and generated IDs, that every part can use.

Guides

  • Models: defining models and their keys, reading and writing them with get, query, scan, put, update, delete and remove, and querying several models at once with DynamoCollection.
  • GraphQL API: registering resolvers, how Python types map to GraphQL, and deploying the router to AppSync.
  • Streams: registering change handlers, how a change finds its handler, and how failures and timeouts are retried.
  • Types: shared field types that are safe to store, such as Datetime, UUID4, Email and UKAddress.
  • Considerations: the limitations and quirks of each part.

Metadata

Release files for aws-pynamo 0.1.0b3

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

Source distribution (sdist)

Source distribution for aws-pynamo 0.1.0b3
File Size Uploaded Provenance Actions
aws_pynamo-0.1.0b3.tar.gz 43.4 kB Without provenance Details for aws_pynamo-0.1.0b3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-pynamo 0.1.0b3
File Interpreter ABI Platform Actions
aws_pynamo-0.1.0b3-py3-none-any.whl Python 3 none any Details for aws_pynamo-0.1.0b3-py3-none-any.whl

Total release size: 97.5 kB

Release files / aws_pynamo-0.1.0b3.tar.gz

Download URL aws_pynamo-0.1.0b3.tar.gz
Size 43.4 kB
Tags Source
SHA-256 checksum
How to use checksums
45fde6d0789d3fdfe1e1ef532a78120f66f5d47e7760459f60e947e30a6f9c14
BLAKE2b-256 checksum
How to use checksums
32941a8be4f472e43f49eb7b65ca4ce2d14093207d9dd83cbb4663bd2b6ca431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / aws_pynamo-0.1.0b3-py3-none-any.whl

Download URL aws_pynamo-0.1.0b3-py3-none-any.whl
Size 54.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
959266f307b1ea7324442e2ee747e374b6509b526dcd04bc012dd9a5edc91233
BLAKE2b-256 checksum
How to use checksums
e7fc569b45d880642394ea17f16865af78cb98315b68f26c3fc9d41c0977bf58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for aws-pynamo 0.1.0b3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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