Skip to main content

Next-generation async ORM for Python with a Rust-powered core

Project description

Ferrum

A next-generation async ORM for Python. Rust-powered engine. Pydantic-native models. Django-inspired developer experience.

Ferrum is an async-first ORM designed for modern Python applications.

Built around a Rust-powered core and a Python-native API, Ferrum combines the ergonomics of Django's ORM, the type safety of Pydantic, and the performance of Rust.

Why Ferrum?

Existing Python ORMs often force developers to choose between:

  • Developer experience
  • Async support
  • Type safety
  • Performance

Ferrum aims to provide all four.

Goals

  • Native async from day one
  • Pydantic-first models
  • Django-inspired ORM experience
  • Rust-powered query engine
  • PostgreSQL-first architecture (MySQL, SQLite, and SQL Server via optional extras)
  • Type-safe query construction
  • Automatic migrations
  • High-performance result hydration
  • Production-ready observability

Quick Example

from ferrum import Model


class User(Model):
    id: int
    email: str
    is_active: bool = True


user = await User.objects.create(
    conn,
    email="john@example.com",
)

users = await (
    User.objects
    .filter(is_active=True)
    .order_by("-id")
    .limit(10)
    .all(conn)
)

async with conn.transaction() as tx:
    user = await User.objects.create(tx, email="jane@example.com")
    await AuditLog.objects.create(tx, user_id=user.id, action="signup")

Features

Async First

No synchronous compatibility layer.

Ferrum is designed around modern async Python applications.

users = await User.objects.all(conn)

Pydantic Native

Models are built directly on top of Pydantic.

class User(Model):
    id: int
    email: str

No duplicate schema definitions.

Django-Inspired API

Familiar query interface.

users = await (
    User.objects
    .filter(email__contains="@gmail.com")
    .order_by("-created_at")
    .all(conn)
)

Rust-Powered Core

Performance-critical components are implemented in Rust:

  • Query compilation
  • SQL generation
  • Result decoding
  • Schema analysis
  • Migration planning

This allows Ferrum to maintain a Pythonic API without sacrificing performance.

Architecture

┌──────────────────────────┐
│      Python API          │
│  Models / QuerySets      │
└────────────┬─────────────┘
             │
             ▼
┌──────────────────────────┐
│      Ferrum Core         │
│      (Rust Engine)       │
├──────────────────────────┤
│ Query Compiler           │
│ SQL AST                  │
│ Result Decoder           │
│ Migration Planner        │
└────────────┬─────────────┘
             │
             ▼
┌──────────────────────────┐
│       PostgreSQL         │
└──────────────────────────┘

Roadmap

v0.1 (complete)

  • PostgreSQL support
  • Basic CRUD operations
  • Async query execution
  • Pydantic models
  • Query builder
  • Type-safe filters
  • Transactions and savepoints
  • Bulk operations (bulk_create, bulk_update, bulk_delete)
  • Migrations (schema diff, apply, revert, CLI)
  • Relationships (ForeignKey, OneToOne, ManyToMany)
  • pgvector KNN search and HNSW/IVFFLAT index DDL
  • Full-text search (TSVector / plainto_tsquery)
  • Observability hooks (Tier A/B/C)
  • CLI (makemigrations, migrate, revert, showmigrations, inspectdb, resetdb)

v0.2 (in progress)

  • Upsert API (upsert, bulk_upsert with conflict targets and RETURNING)
  • Composite primary keys
  • Array field types (uuid[], text[], scalar arrays)
  • JSONB operators (__contains, __has_key)
  • RLS / tenant session helpers (set_config, tenant_session)
  • call_function for allowlisted stored-procedure calls
  • Migration ops for extensions, RLS policies, and function DDL
  • pgvector similarity score projection (vector_search helper)
  • Query optimization (deferred fields, prefetch tuning)
  • Advanced relationship loading

v1.0

  • Production-ready stability
  • Performance benchmarking suite
  • Full documentation site

Project Status

Ferrum is currently in active development.

The API is not yet stable and breaking changes should be expected until the first public release.

Installation

# PostgreSQL (most common)
pip install 'ferrum-orm[pg]'

# PostgreSQL + migrations CLI
pip install 'ferrum-orm[pg,cli]'

# MySQL
pip install 'ferrum-orm[mysql]'

# SQLite + migrations CLI (testing / local dev)
pip install 'ferrum-orm[sqlite,cli]'

# SQL Server (also needs a system ODBC driver, e.g. msodbcsql18)
pip install 'ferrum-orm[mssql]'

# Optional MessagePack wire format for the Python<->Rust boundary
pip install 'ferrum-orm[msgpack]'

# Everything (all drivers + CLI + dotenv)
pip install 'ferrum-orm[all]'

# Core ORM only (no database driver — install a driver extra before connecting)
pip install ferrum-orm

Bare ferrum-orm installs Pydantic and the Rust core only. Choose a driver extra (pg, mysql, sqlite, or mssql) before calling ferrum.connect().

MySQL, SQLite, and SQL Server are thin-parity backends: they support core CRUD and migrations but not transactions, upsert, bulk_update, RLS, or pgvector (PostgreSQL only). SQL Server connects via aioodbc/pyodbc and requires a system ODBC driver such as msodbcsql18; DSNs use the mssql:// or sqlserver:// scheme.

Wire format (advanced)

The Python↔Rust IR/hydration boundary defaults to JSON. Installing the msgpack extra lets you switch it to MessagePack, selected via the FERRUM_WIRE_FORMAT environment variable (json | msgpack) or the [ferrum] wire_format key in ferrum.toml / pyproject.toml. JSON remains the default; MessagePack is opt-in.

From source, build the native extension with maturin develop (or mise run dev).

Examples

Runnable samples live under examples/:

Contributing

Contributions are welcome. Start with CONTRIBUTING.md for local setup, scoped verification, architecture rules, and pull request expectations.

License

Apache License 2.0

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

ferrum_orm-0.1.3.tar.gz (154.3 kB view details)

Uploaded Source

Built Distributions

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

ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl (776.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl (758.3 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

ferrum_orm-0.1.3-cp311-abi3-macosx_11_0_arm64.whl (711.0 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

ferrum_orm-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl (738.7 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file ferrum_orm-0.1.3.tar.gz.

File metadata

  • Download URL: ferrum_orm-0.1.3.tar.gz
  • Upload date:
  • Size: 154.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ferrum_orm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ec7c97ec2e579dfdd2b46f4fa3f6481bb8a6c5e09b48f03769265de3eb8c2169
MD5 260139a76e2398ec00594ebb62f99956
BLAKE2b-256 4b8b504b8e6008166c07487a669bc6fa07cd1c4fa023d7967e91dc984809dc9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ferrum_orm-0.1.3.tar.gz:

Publisher: release.yml on ferrum-orm/ferrum

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

File details

Details for the file ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a8a51792e0d4972d41b8470f6867197327b41639e99084cf25aaf30009281c79
MD5 579f917d261290ba2af0202529b72507
BLAKE2b-256 abcb5465cc728c64842e0f309531fad6cbaaf6fdc3c5e40390ec69c3870db36e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on ferrum-orm/ferrum

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

File details

Details for the file ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4184ccee3d3552e437df9804d0c2f8ec41754c548c749853f1a34f358030e494
MD5 249c746b6bee63519a911fe7b704c646
BLAKE2b-256 b4adba87789d783278d58d2b7c2f72322a96c72f76a1a92174111546208c4ad6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ferrum_orm-0.1.3-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on ferrum-orm/ferrum

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

File details

Details for the file ferrum_orm-0.1.3-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ferrum_orm-0.1.3-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c209f7a6542cc914faab4a2a90369efd65bee771ed53b0bdf2aff043cd361d76
MD5 8d2ef1e6c9b652eaa8c9f807caaa68f1
BLAKE2b-256 a746104af66b889070dfe0bf373c23a4249506e69b704025bf8cfbb3b44403e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ferrum_orm-0.1.3-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on ferrum-orm/ferrum

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

File details

Details for the file ferrum_orm-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ferrum_orm-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fb994d3a079a2ef27899b7dc849690722d54dc6b782ca04802db7b72a1413578
MD5 e2bfa459cc6cf7e5d482ebedc63747ed
BLAKE2b-256 3bc5932bdad456dcf59074e15c85693b149c320f3deb5e812b6b238600aff366

See more details on using hashes here.

Provenance

The following attestation bundles were made for ferrum_orm-0.1.3-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on ferrum-orm/ferrum

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