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.

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.
  • Considerations: the limitations and quirks of each part.

Metadata

Release files for aws-pynamo 0.1.0b2

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

Built distribution (wheel)

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

Total release size: 87.6 kB

Release files / aws_pynamo-0.1.0b2.tar.gz

Download URL aws_pynamo-0.1.0b2.tar.gz
Size 39.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9138c02111e62b81930be098ae25d4b4b6e73b46bb5c8daa6403d5768ee2f42c
BLAKE2b-256 checksum
How to use checksums
e705881f3f713d9fd196f4b88b82a047e8c9a6787ceb53ea6ac264ac2a63e635
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.0b2-py3-none-any.whl

Download URL aws_pynamo-0.1.0b2-py3-none-any.whl
Size 48.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32434a098fb7d25a1b2695a9f7fef7649b46ae26dc3e6614e4eb5ee49746f33f
BLAKE2b-256 checksum
How to use checksums
51e26dcdc163fbb54e455b59204e831f8cedc09c657b826986d510f1fbba0685
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.0b2

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