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.0b4

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.0b4
File Size Uploaded Provenance Actions
aws_pynamo-0.1.0b4.tar.gz 43.3 kB Without provenance Details for aws_pynamo-0.1.0b4.tar.gz

Built distribution (wheel)

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

Total release size: 97.3 kB

Release files / aws_pynamo-0.1.0b4.tar.gz

Download URL aws_pynamo-0.1.0b4.tar.gz
Size 43.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a15b715fd6a4949e6daf3de3dcdb7e223f5ea8c00a9e6ff19ced5601e17c3b71
BLAKE2b-256 checksum
How to use checksums
0b793176dff0c6241937b1864cd1bc27abdd651193076ffd50847dbccd144e95
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.0b4-py3-none-any.whl

Download URL aws_pynamo-0.1.0b4-py3-none-any.whl
Size 54.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d21034cbb5adcc7499b207756a86804b661ca4990c7094e0f43f2079b58e7efc
BLAKE2b-256 checksum
How to use checksums
00c9d80cdbedccd79e74fd39f3b19072ea442a73e2b2d13ebeaa66b894d37f18
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.0b4

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