Skip to content

Dynantic

Dynantic

Type-safe DynamoDB ORM with Pydantic validation

License: MIT Python 3.10+ PyPI Code style: ruff Type checked: mypy


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, and more
  • ✅ Global Secondary Indexes (GSI)
  • ✅ Polymorphic models for single-table design
  • ✅ Conditional writes with SQLModel-like syntax
  • ✅ Atomic updates without fetching first
  • ✅ External pagination for stateless APIs
  • ✅ 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-safe create()

Optimized for: AWS Lambda, serverless functions, FastAPI (with threadpool), 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")
print(f"User: {user.name}, Status: {user.status.value}")

# Update (atomic)
User.update("user-123", "john@example.com") \
    .add(User.balance, 10.0) \
    .add(User.tags, {"early_adopter"}) \
    .execute()

# Delete
User.delete("user-123", "john@example.com")

Why Dynantic?

Dynantic PynamoDB Raw boto3
Pydantic v2 validation ✅ ❌ ❌
Type-safe queries ✅ ✅ ❌
IDE autocomplete ✅ Partial ❌
Lambda-optimized (sync) ✅ ✅ ✅
Batch + Transactions ✅ ✅ ✅
Polymorphism ✅ ❌ ❌
Learning curve Low Medium High

Beta Software

Dynantic is in active development. The API is stable, but you may encounter rough edges. Production use is at your own risk. Feedback and contributions are welcome!