Skip to main content

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

# Insert from an instance (sentinel PK is dropped so the DB default runs)
draft = User(id=0, email="dana@example.com")
created = await User.objects.create(conn, draft)

# Persist one instance's changes by primary key
created.is_active = False
await User.objects.update_instance(conn, created, fields=["is_active"])

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.

Field Options

ferrum.Field() accepts column-level constraints that are carried through to DDL:

Parameter Type Description
db_default str | None DB-side DEFAULT expression (e.g. "NOW()", "''", "GEN_RANDOM_UUID()"). Token casing is normalised (now() → NOW()).
nullable bool | None Override annotation-derived nullability. Use nullable=False to force NOT NULL even on a T | None-annotated field.
db_index bool Emit a CREATE INDEX on this column (auto-named idx_{table}_{field}).
unique bool Emit a UNIQUE constraint.
db_column str | None Override the database column name.
primary_key bool Declare this field as the primary key.
uuid_generate "v4" | "v7" | None Set GEN_RANDOM_UUID() / UUIDV7() as the DB default for UUID PK columns.
max_length int | None Emit VARCHAR(n) instead of TEXT.
max_digits / decimal_places int | None Emit NUMERIC(p,s).
vector_dimensions int | None Required for Vector columns; emits VECTOR(n).
from datetime import datetime
from typing import Annotated
from ferrum import Model, Field

class Event(Model):
    id: int
    # DB-side timestamp default; Python annotation allows None but column is NOT NULL
    created_at: Annotated[datetime | None, Field(db_default="now()", nullable=False)]
    # Indexed text column
    kind: Annotated[str, Field(db_index=True, max_length=64)]

makemigrations honours these field attributes:

  • db_default / nullable are written into CREATE TABLE and ADD COLUMN DDL.
  • db_index=True emits CREATE INDEX after the table op.
  • For already-existing tables, makemigrations now autodiffs index and column attribute changes against the state projected from prior migration files:
    • Adding db_index=True to an existing field → AddIndex op.
    • Removing db_index=True → DropIndex op.
    • Adding or changing db_default → AlterColumn … SET DEFAULT … op.
    • Removing db_default → AlterColumn … DROP DEFAULT op.
    • Changing nullability → AlterColumn … SET / DROP NOT NULL op (SET NOT NULL is classified destructive and requires --confirm).
    • Column type changes, renames, and drops remain manual (out of scope for v0.1).

Django-Inspired API

Familiar query interface.

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

First-Class IDE Support

Ferrum ships a PEP 561 py.typed marker, so editors and type checkers (mypy, pyright, ty) resolve its inline hints out of the box. Model.objects is typed as QuerySet[YourModel], chaining preserves the model type, and terminals infer precise results — no casts:

users: list[User] = await User.objects.filter(is_active=True).all(conn)   # list[User]
user: User | None = await User.objects.first(conn)                        # User | None
rows: list[dict[str, Any]] = await User.objects.values("id", "email").all(conn)
ids: list[Any] = await User.objects.values_list("id", flat=True).all(conn)

values() / values_list() return dedicated ValuesQuerySet, ValuesListQuerySet, and FlatValuesListQuerySet variants (all exported from ferrum) so all() returns list[dict[str, Any]], list[tuple[Any, ...]], or list[Any] respectively.

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.

Native full-text search across PostgreSQL, MySQL, SQLite FTS5, and SQL Server — one QuerySet API, dialect-specific SQL emit and migration DDL.

Query modes (filter lookups and ranking):

Mode Lookup operator Typical use
plain __match Natural-language terms
phrase __match_phrase Exact phrase
websearch __match_websearch Web-style quotes, - negation
boolean __match_boolean Boolean operators (&, |, !)

Convenience methods:

# Filter + relevance ranking in one call
hits = await Article.objects.search(
    "python async orm", field="body", mode="websearch"
).limit(10).all(conn)

# Rank without an implicit filter
ranked = await Article.objects.rank_by("body", "rust", mode="plain").all(conn)

Index declaration — PostgreSQL uses TSVector columns; other drivers index base text columns via Meta.full_text_indexes:

from ferrum.models import Field, FullTextIndex

class Article(Model):
    search_vector: Annotated[TSVector, Field(fts_config="english")] | None = None
    body: str = ""

    class Meta:
        full_text_indexes = [FullTextIndex(fields=("body",), config="english")]

Query strings are always bound parameters; fts_config and index names come from model-metadata allowlists only. See Getting Started → Vector and full-text columns and API Reference for per-dialect DDL and operator mapping.

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 (cross-dialect: PostgreSQL, MySQL, SQLite FTS5, SQL Server)
  • 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)
  • Field(db_default=..., nullable=...) — first-class DB-side defaults and nullability override
  • makemigrations autodiff for index / default / nullability changes on existing tables
  • 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

Metadata

Release files for ferrum-orm 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ferrum-orm 0.1.11
File Size Uploaded
ferrum_orm-0.1.11.tar.gz 180.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ferrum-orm 0.1.11
File
ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
ferrum_orm-0.1.11-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
ferrum_orm-0.1.11-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.4 MB

Release files / ferrum_orm-0.1.11.tar.gz

Download URL ferrum_orm-0.1.11.tar.gz
Size 180.5 kB
Tags Source
SHA-256 checksum
How to use checksums
07f1230b2aa69d6c1f2d8e3b6c84ff28709a964f4399c70369cb80691d16282f
BLAKE2b-256 checksum
How to use checksums
1895a47cd07a70f2c904ae93cf0bfed6d2a2cf2fd26d0caeef9404d366f49357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_x86_64.whl
Size 841.8 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
f72768eaeec7bf0f16d5bc187ecc535c5461dca05f642df2b22a9b9f6513ea22
BLAKE2b-256 checksum
How to use checksums
3349e7b1c890b6c984792577d1bba54b900713a9b04d1ab80d4a23a514cf2a67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL ferrum_orm-0.1.11-cp311-abi3-manylinux_2_28_aarch64.whl
Size 819.8 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
b085764a599c294cbec9ddf8a2252c92fdffc8995c264770dd7185f7c431a54d
BLAKE2b-256 checksum
How to use checksums
9b6c685f78ffead17a6c883a00454db826c8baf3f0af0aaff6b47aed13f53d7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / ferrum_orm-0.1.11-cp311-abi3-macosx_11_0_arm64.whl

Download URL ferrum_orm-0.1.11-cp311-abi3-macosx_11_0_arm64.whl
Size 768.9 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9945df4afd2ab708944e998a6537a7b93c967280aa3b7f3f2d36b0f446ab371e
BLAKE2b-256 checksum
How to use checksums
849883a930eac298c68e880f4a55c8165bf9fa7f2c317f08d8e67c370dadd25d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / ferrum_orm-0.1.11-cp311-abi3-macosx_10_12_x86_64.whl

Download URL ferrum_orm-0.1.11-cp311-abi3-macosx_10_12_x86_64.whl
Size 802.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
74129ee58a45f5a07ceed68498d403bc038d3f6de3807368fef5786f01034eb2
BLAKE2b-256 checksum
How to use checksums
0bcfcdffb75a9b270e13b5c60aa8fa57fa6011b3200420de68df3462a82cc2c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.17

5 release files

0.1.15

5 release files

0.1.14

5 release files

0.1.13

5 release files

This release

0.1.11 This release

5 release files

0.1.9

5 release files

0.1.8

5 release files

0.1.7

5 release files

0.1.6

5 release files

0.1.5

5 release files

0.1.4

5 release files

0.1.3

5 release files

0.1.2

5 release files

0.1.1

5 release files

0.1.0

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page