Skip to content

yezz123/ormdantic

Repository files navigation

Logo

A Rust-backed async ORM for Python applications that use Pydantic models.

Test Coverage Package version Supported Python versions CodSpeed Badge

Ormdantic lets you declare database tables with Pydantic v2 models and run async CRUD, relationship loading, migrations, reflection, and native SQL execution through a Rust-backed runtime.

The project is designed for applications that want Python model ergonomics without giving up SQL database features. Python owns the model and API surface; Rust owns SQL compilation, type conversion, and driver execution.

What You Get

Area What Ormdantic Provides
Models Pydantic models decorated as database tables.
CRUD Async insert, update, upsert, delete, find, count, and bulk update helpers.
Queries Dictionary filters for simple cases and expression objects for advanced SQL.
Relationships Explicit joined and select-in loaders, plus explicit relationship loading.
Transactions Async transaction and session contexts.
Migrations Snapshots, diffs, plans, migration artifacts, history, rollback, repair, and squash helpers.
Reflection Live database inspection for tables, columns, indexes, constraints, schemas, views, sequences, and dialect metadata.
Drivers SQLite, PostgreSQL, MySQL, MariaDB, SQL Server, and Oracle through the native runtime.

Install

uv add ormdantic

First Example

from pydantic import BaseModel, Field

from ormdantic import Ormdantic

db = Ormdantic("sqlite:///app.sqlite3")


@db.table(pk="id", indexed=["name"])
class Flavor(BaseModel):
    id: str
    name: str = Field(min_length=2, max_length=63)
    rating: int = 0


async def main() -> None:
    await db.init()

    await db[Flavor].insert(Flavor(id="vanilla", name="Vanilla", rating=5))

    result = await db[Flavor].find_many(
        {"rating": {"gte": 4}},
        order_by=["name"],
    )

    for flavor in result.data:
        print(flavor.name)

Learn The Project

Start with the documentation when you are new:

  • docs/quickstart.md shows the smallest useful workflow.
  • docs/concepts/ explains tables, fields, relationships, querying, loading, sessions, migrations, events, and the native engine.
  • docs/drivers/ explains SQLite, PostgreSQL, MySQL, MariaDB, SQL Server, and Oracle behavior.
  • docs/examples/ contains runnable beginner and advanced guides.
  • docs/api/ documents the Python API with generated references and usage notes.

Development

Common commands:

bash scripts/lint.sh
bash scripts/test.sh
bash scripts/docs_build.sh

The docs use Zensical:

uv run --group docs zensical build
uv run --group docs zensical serve

Rust crates live under rust/crates/ and are managed from the repository root Cargo.toml.

Status

Ormdantic is evolving quickly. Prefer explicit migrations, review generated SQL before applying it in production, and check the driver-specific pages for dialect behavior.

About

Asynchronous ORM that uses pydantic models to represent database tables ✨

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors

Languages