Skip to main content
Pre-release

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

PynamoDB Single Table

A Pydantic ORM built on top of PynamoDB.

PyPI Status Python Version License

Read the documentation at https://pynamodb-single-table.readthedocs.io/ Tests Codecov

pre-commit Black

Features

Provides a Django-inspired "Active Record"-style ORM using single-table design built on top of DynamoDB.

import abc
from datetime import datetime
from pydantic import Field, EmailStr
from pynamodb_single_table import SingleTableBaseModel

class BaseTableModel(SingleTableBaseModel, abc.ABC):
    class _PynamodbMeta:
        table_name = "MyDynamoDBTable"

class User(BaseTableModel):
    __table_name__ = "user"
    __str_id_field__ = "username"
    username: str
    email: EmailStr
    account_activated_on: datetime = Field(default_factory=datetime.now)

# Make sure the table exists in DynamoDB
BaseTableModel.ensure_table_exists(billing_mode="PAY_PER_REQUEST")

# Create a record
john, was_created = User.get_or_create(username="john_doe", email="john.doe@email.com")
assert was_created

# Retrieve
john_again = User.get_by_str("john_doe")
assert john_again.email == "john.doe@email.com"

# Update
now = datetime.now()
john_again.account_activated_on = now
john_again.save()

assert User.get_by_str("john_doe").account_activated_on == now

# Delete
john_again.delete()

Motivation

Many use cases need little more than structured CRUD operations with a table-like design (e.g., for storing users and groups), but figuring out how to host that efficiently in the cloud can be a pain.

DynamoDB is awesome for CRUD when you have clean keys. It's a truly serverless NoSQL database, including nice features like:

  • High performance CRUD operations when you know your primary keys
  • Scale-to-zero usage-based pricing available
  • Official local testing capability
  • Conditional CRUD operations to avoid race conditions
  • Multiple methods of indexing into data
  • Scalable with reliable performance

This project, in part, emerges from my frustration with the lack of many truly serverless SQL database services. By "truly serverless", I mean purely usage-based pricing (generally a combination of storage costs and query costs). Many small, startup applications use trivial amounts of query throughput and story trivial amounts of data, but finding a way to deploy such an application into the cloud without shelling out $10-$100's per month is tricky. In AWS, now that Aurora Serverless V1 is being replaced, there is no way to do this.

However, DynamoDB provides not just the basic functionality needed to do this, it's actually a really good option if your data usage patterns can fit within its constraints. That means, primarily, that you can always do key-based lookups, and that you can avoid changing your indexing strategy or database schema too much (e.g. modifying a table from having nullable columns into non-nullable). DynamoDB can do custom queries at tolerable rates, but you're going to get sub-par speed and cost efficiency if you're regularly doing searches across entire tables instead of direct hash key lookups.

Requirements

This project is built on the backs of Pydantic and Pynamodb. I am incredibly grateful to the developers and communities of both of those projects.

Installation

You can install PynamoDB Single Table via pip from PyPI:

$ pip install pynamodb_single_table

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, PynamoDB Single Table is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.

Metadata

Release files for pynamodb-single-table 0.1.4.dev1717448472

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

Source distribution (sdist)

Source distribution for pynamodb-single-table 0.1.4.dev1717448472
File Size Uploaded Provenance
pynamodb_single_table-0.1.4.dev1717448472.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pynamodb-single-table 0.1.4.dev1717448472
File Interpreter ABI Platform
pynamodb_single_table-0.1.4.dev1717448472-py3-none-any.whl Python 3 none any Details

Total release size: 13.1 kB

Release files / pynamodb_single_table-0.1.4.dev1717448472.tar.gz

Download URL pynamodb_single_table-0.1.4.dev1717448472.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
68606ca469450ebcb3531b35c1083b4dd5ce2d51ca3f207e0a3d4a83882f94e3
BLAKE2b-256 checksum
How to use checksums
c0817c189bf1e3be4aff66c916ee163a3ebb3bd463f3e7e60dbf66013a0140ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / pynamodb_single_table-0.1.4.dev1717448472-py3-none-any.whl

Download URL pynamodb_single_table-0.1.4.dev1717448472-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59375fc3242a2f565b6a731351f8e19e853059a603d2cae7a59934c59f61ab83
BLAKE2b-256 checksum
How to use checksums
98468fd6f086e5f79d7de36acd399eff4a1ad9371dd737b985ee213066f753be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Security for pynamodb-single-table 0.1.4.dev1717448472

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.

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