Skip to main content

Pydantic ODM for DynamoDB based on Boto3

Project description

Dynantic

Dynantic

Type-safe DynamoDB ORM with Pydantic validation

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

Read the Documentation


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-safe create()

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")

Full documentation and guides

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests and ensure they pass (uv run pytest)
  4. Run type checking (uv run mypy dynantic)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynantic-0.4.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynantic-0.4.0-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

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

Hashes for dynantic-0.4.0.tar.gz
Algorithm Hash digest
SHA256 87f5dcf491116a4a8bc0e0ef31919dd7b4e57af14f04a67ffc473ad749c33f6f
MD5 158ef740b7ab5275d958e1eafbdd80e5
BLAKE2b-256 98f818638912f9e5fabcf36f0e3c615a13d9073dba7d3c2d637c9169dcfbc0a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynantic-0.4.0.tar.gz:

Publisher: publish.yml on Simi24/dynantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for dynantic-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f433f7101044d8e4ad0e9e872b99a9b3e0f426be820162d40cd1f10a4355cc37
MD5 9d30dc0718015f9cd5039aa569f1a6db
BLAKE2b-256 8ad0261d686ec84e617a3bc66a82824c8011e4327ecb54446ad58415d83b4c9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynantic-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Simi24/dynantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page