Pydantic ODM for DynamoDB based on Boto3
Project description
Dynantic
Type-safe DynamoDB ORM with Pydantic validation
Dynantic is a synchronous-first Python ORM for Amazon DynamoDB that combines Pydantic v2 validation with an elegant query DSL.
Features
- Pydantic v2 validation and type safety
- Metaclass-based DSL for elegant query building
- Comprehensive type support (datetime, UUID, Enum, Decimal, sets, etc.)
- Global Secondary Indexes (GSI)
- Polymorphic models for single-table design
- Conditional writes with SQLModel-like syntax
- Atomic updates without fetching first (
add,set_if_not_exists,append) - Projection queries (
.values()) and server-side counts (.count()) - Batch operations with auto-chunking and retry
- ACID transactions across tables
- TTL support with automatic datetime/epoch conversion
- Auto-UUID with
Key(auto=True)and INSERT-safecreate()
Optimized for: AWS Lambda, serverless functions, FastAPI, batch jobs, and scripts.
Installation
pip install dynantic
Requirements: Python 3.10+ · pydantic >= 2.6.0 · boto3 >= 1.34.0
Quick Start
from datetime import datetime, timezone
from enum import Enum
from dynantic import DynamoModel, Key, SortKey
class UserStatus(Enum):
ACTIVE = "active"
INACTIVE = "inactive"
class User(DynamoModel):
user_id: str = Key()
email: str = SortKey()
name: str
status: UserStatus
created_at: datetime
balance: float
tags: set[str]
class Meta:
table_name = "users"
# Create
user = User(
user_id="user-123",
email="john@example.com",
name="John Doe",
status=UserStatus.ACTIVE,
created_at=datetime.now(timezone.utc),
balance=99.99,
tags={"premium", "verified"}
)
user.save()
# Read
user = User.get("user-123", "john@example.com")
# Update (atomic)
User.update("user-123", "john@example.com") \
.add(User.balance, 10.0) \
.execute()
# Delete
User.delete("user-123", "john@example.com")
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Write tests and ensure they pass (
uv run pytest) - Run type checking (
uv run mypy dynantic) - Submit a pull request
git clone https://github.com/Simi24/dynantic.git
cd dynantic
uv sync --dev
docker compose up -d # Start LocalStack
uv run pytest
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynantic-0.4.0.tar.gz.
File metadata
- Download URL: dynantic-0.4.0.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87f5dcf491116a4a8bc0e0ef31919dd7b4e57af14f04a67ffc473ad749c33f6f
|
|
| MD5 |
158ef740b7ab5275d958e1eafbdd80e5
|
|
| BLAKE2b-256 |
98f818638912f9e5fabcf36f0e3c615a13d9073dba7d3c2d637c9169dcfbc0a7
|
Provenance
The following attestation bundles were made for dynantic-0.4.0.tar.gz:
Publisher:
publish.yml on Simi24/dynantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dynantic-0.4.0.tar.gz -
Subject digest:
87f5dcf491116a4a8bc0e0ef31919dd7b4e57af14f04a67ffc473ad749c33f6f - Sigstore transparency entry: 1823584290
- Sigstore integration time:
-
Permalink:
Simi24/dynantic@ca6e5588a35c1b44fe0eb56fbbf45b3da4635b69 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Simi24
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca6e5588a35c1b44fe0eb56fbbf45b3da4635b69 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file dynantic-0.4.0-py3-none-any.whl.
File metadata
- Download URL: dynantic-0.4.0-py3-none-any.whl
- Upload date:
- Size: 39.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f433f7101044d8e4ad0e9e872b99a9b3e0f426be820162d40cd1f10a4355cc37
|
|
| MD5 |
9d30dc0718015f9cd5039aa569f1a6db
|
|
| BLAKE2b-256 |
8ad0261d686ec84e617a3bc66a82824c8011e4327ecb54446ad58415d83b4c9b
|
Provenance
The following attestation bundles were made for dynantic-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on Simi24/dynantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dynantic-0.4.0-py3-none-any.whl -
Subject digest:
f433f7101044d8e4ad0e9e872b99a9b3e0f426be820162d40cd1f10a4355cc37 - Sigstore transparency entry: 1823584341
- Sigstore integration time:
-
Permalink:
Simi24/dynantic@ca6e5588a35c1b44fe0eb56fbbf45b3da4635b69 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Simi24
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca6e5588a35c1b44fe0eb56fbbf45b3da4635b69 -
Trigger Event:
workflow_dispatch
-
Statement type: