This release is a pre-release and may not be stable for production use.
pynamo
Documentation · Source · Changelog
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:
- Stored:
pynamo.modelsreads and writes the models in a DynamoDB table, building every key from the model's own attributes. - Served:
pynamo.apipublishes functions that take and return the models as an AppSync GraphQL API, generating the schema from their type hints. - Reacted to:
pynamo.streamshands 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.modelsis a complete DynamoDB ORM without the API or streams.pynamo.apiserves any pydantic model, not justDynamoModels, so it can front data stored elsewhere.pynamo.streamsvalidates 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,deleteandremove, and querying several models at once withDynamoCollection. - 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,UUID,UUID4,EmailandUKAddress. - API reference: every public class and function, generated from the docstrings.
- Considerations: the limitations and quirks of each part.
Metadata
Release files for aws-pynamo 0.1.0b7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aws_pynamo-0.1.0b7.tar.gz | 56.8 kB | Without provenance | Details for aws_pynamo-0.1.0b7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aws_pynamo-0.1.0b7-py3-none-any.whl | Python 3 | none | any | Details for aws_pynamo-0.1.0b7-py3-none-any.whl |
Total release size: 127.4 kB
Release files / aws_pynamo-0.1.0b7.tar.gz
| Download URL | aws_pynamo-0.1.0b7.tar.gz |
|---|---|
| Size | 56.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c90105513fdf59ebc98789446b2f1e498920d232b861a167b8b2fb024f3ef06b
|
|
BLAKE2b-256 checksum How to use checksums |
4549eaa31597bcce58744b730e8659b795e95af43aa5655b04c0ce7a45ec114a
|
| 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.0b7-py3-none-any.whl
| Download URL | aws_pynamo-0.1.0b7-py3-none-any.whl |
|---|---|
| Size | 70.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfe6e0ab5e2f066f62f3a92dfc7e38b4a4b23dc0de1486e79e4fb2b69e011a61
|
|
BLAKE2b-256 checksum How to use checksums |
587dc726f269b526f71c999cb3c5b33b31968b394c55b38cd44e125f9f27c4f0
|
| 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.0b7
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.