Skip to main content

Ferronit

English · Русский

PyPI Python License GitHub stars

⚠️ Early development — not production-ready. The API and internals are still changing; use at your own risk.

Your legacy Python service is hitting its performance ceiling. Ferronit moves the hot path — routing, request parsing, JSON, gzip, CORS, PostgreSQL — into a Rust core, while your handlers stay plain Python. A migration, not a rewrite.

Documentation: docs/ — quick start, routing, requests, dependency injection, the data layer (rawdb + rawmodel), DDD/DI, the Rust core, benchmarks, ASVS. (Docs are currently written in Russian.)

Installation

pip install ferronit        # installs the Python layer and the native core together

Ferronit is a single package built with maturin as a mixed project. The core (ferronit._core) is compiled with the abi3-py312 feature, so one wheel works on every CPython from 3.12 to 3.15+. Its only runtime dependency is msgspec (fast JSON/validation). Database drivers are extras — ferronit[postgres] (asyncpg), ferronit[mysql], ferronit[sqlite] — and the data layer imports them lazily, when a pool is created.

# app.py
from ferronit import Ferronit

app = Ferronit()

@app.route("/hello/{name}")
async def hello(name: str):
    return {"hello": name}
ferronit dev                          # dev server (uvicorn, reload)
ferronit dev --server granian         # granian (Rust, ~4× faster)
ferronit run --workers 4              # production: granian, uvicorn fallback

Why it is fast

Routing is Rust matchit, effectively O(1). On database reads the framework stays within ~15% of raw Python asyncpg, is within 1.2–1.9× of a raw Go driver (pgx) and 1.3–1.9× behind Rust frameworks (Axum/Actix; the gap narrows to ~1.3× at 1000 rows), beats BlackSheep by ~4.6–5.4× and FastAPI/Django by an order of magnitude: typed row models + msgspec reply building cost tens of microseconds, not multiples. Methodology — ab (C client) only, granian/net/http, 1 worker, 3 rounds; the rows stages were measured one per run (no long shared session), see ferronit-bench/docs/benchmarks.md. On the JWT stage the cost is the verifier, not the framework: Python stacks pay ~18–29 µs for PyJWT's pure-Python HS256 decode (Rust/Go verify in ~1–6 µs), so Ferronit edges out BlackSheep by ~15% and is 5.1× ahead of FastAPI.

Scenario Ferronit BlackSheep FastAPI Go pgx Rust Axum
GET /ping (dict) 117 536 req/s 82 822 req/s 18 777 req/s 107 461 req/s 206 139 req/s
GET /me (JWT HS256) 24 239 req/s 21 129 req/s 4 760 req/s 65 607 req/s 152 957 req/s
GET /rows?limit=100 5 037 req/s 995 req/s 630 req/s 6 221 req/s 7 204 req/s
GET /rows?limit=1000 697 req/s 130 req/s 82 req/s 834 req/s 887 req/s

Rows reading and ping/JWT were measured in separate runs on the same day (dates in benchmarks.md), so absolutes may shift by 2–10% across rows; ratios within a row are like-for-like.

Data layer

One thin layer over the driver — rawdb + rawmodel: PostgreSQL (asyncpg), MySQL (aiomysql) and SQLite (aiosqlite) behind the same API. Declarative models, a query DSL (select), relations, a Unit of Work — no ORM. SQL is built from an expression tree and compiled per dialect. Details: docs/data/overview.md.

from typing import Annotated
from ferronit import Ferronit
from ferronit.contrib.rawdb import create_pool
from ferronit.contrib.rawmodel import Model, Relation

class OrderItem(Model):
    __table__ = "order_items"
    id: int = 0
    order_id: int = 0
    name: str = ""

class Order(Model):
    __table__ = "orders"
    id: int = 0
    items: Annotated[list[OrderItem], Relation("order_id")] = []   # 1:N, always loaded

app = Ferronit()

@app.route("/orders")
async def orders():
    pool = await create_pool("postgresql://user:pass@localhost/db")  # usually lifespan/DI
    async with pool.uow(readonly=True) as uow:
        rows = await uow.model(Order).list(limit=10)
    return {"orders": rows}   # items nested in JSON, one WHERE fk = ANY($1)

Development

poetry install --all-extras             # environment in .venv + all dependencies
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 poetry run maturin develop --release   # build the Rust core
./scripts/check.sh                      # lint → types → docstrings → core build → tests
poetry run pytest tests/ -q             # 554 tests

Poetry manages the environment (poetry.toml keeps the venv inside the project), while the wheel carrying the Rust core is built by maturin (see [tool.maturin] in pyproject.toml), so Poetry itself never installs the project.

  • AGENTS.md — guidance for code agents (Claude Code, Codex, Cursor, …).
  • examples/ — minimal, DI, LLM + SSE, RAG, WebSocket; examples/app.py is the DDD example.
  • The package ships py.typed; type stubs for the Rust core live in ferronit/_core.pyi.
  • ferronit-bench — the measurement rig behind every number above (methodology, scripts, charts); not part of the package.

Release

# the version lives in two files: ferronit/__init__.py and ferronit-rs/Cargo.toml
git tag -a v0.25.0 -m "Ferronit 0.25.0" && git push origin v0.25.0

Pushing a v* tag triggers .github/workflows/release.yml: checks and tests → wheels (Linux glibc/musl, macOS, Windows) and sdist → GitHub Release with the artifacts → publish to PyPI (API token from the PYPI_API_TOKEN repository secret). If the tag version does not match Cargo.toml/__init__.py, the workflow fails before publishing anything.

Docker

docker build -t ferronit:0.25.0 .
docker run --rm -p 8000:8000 ferronit:0.25.0

License

Apache License 2.0 — see LICENSE. Use, modification and distribution are permitted, including commercial use; copyright notices and the patent grant must be preserved.

Metadata

Release files for ferronit 0.25.0

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

Source distribution (sdist)

Source distribution for ferronit 0.25.0
File Size Uploaded Provenance Actions
ferronit-0.25.0.tar.gz 121.6 kB Without provenance Details for ferronit-0.25.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ferronit 0.25.0
File Actions
ferronit-0.25.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for ferronit-0.25.0-cp312-abi3-win_amd64.whl
ferronit-0.25.0-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details for ferronit-0.25.0-cp312-abi3-musllinux_1_2_x86_64.whl
ferronit-0.25.0-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for ferronit-0.25.0-cp312-abi3-manylinux_2_28_x86_64.whl
ferronit-0.25.0-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for ferronit-0.25.0-cp312-abi3-manylinux_2_28_aarch64.whl
ferronit-0.25.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for ferronit-0.25.0-cp312-abi3-macosx_11_0_arm64.whl
ferronit-0.25.0-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details for ferronit-0.25.0-cp312-abi3-macosx_10_12_x86_64.whl

Total release size: 3.0 MB

Release files / ferronit-0.25.0.tar.gz

Download URL ferronit-0.25.0.tar.gz
Size 121.6 kB
Tags Source
SHA-256 checksum
How to use checksums
71868d5eae356417f8de45adaa53cf4c6a3113257841a9d1fbbffeb20decd784
BLAKE2b-256 checksum
How to use checksums
fbeec0d627764661c86eb8fb257f8df50c1eaa744b1d48eea09cc7517c1efdbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-win_amd64.whl

Download URL ferronit-0.25.0-cp312-abi3-win_amd64.whl
Size 383.6 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
cb6b60ec0d21317296e7cd561940013fc5a4be5ade96038227b8deccfaa5dfff
BLAKE2b-256 checksum
How to use checksums
75707e486ec8c75c35acae74ab876b2d5c3bd71e6320447926ad4644b22e86d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL ferronit-0.25.0-cp312-abi3-musllinux_1_2_x86_64.whl
Size 680.7 kB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
f3aba6e06a1be5fff9e889762fcd78fdec8b7d1c8ca04872fe302ed63a89f617
BLAKE2b-256 checksum
How to use checksums
fb013dd8bed83487bceaf72ba1b25096177203e57bc1e94a528286d286228fdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL ferronit-0.25.0-cp312-abi3-manylinux_2_28_x86_64.whl
Size 470.5 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
58ca0d675881be0da09f035e325ddc23e27dc43d47ccef2509e1aad045577379
BLAKE2b-256 checksum
How to use checksums
61cf00985004d689868a5fb4f954fdf1243517b6b60711f6752d3bc93f3c092c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL ferronit-0.25.0-cp312-abi3-manylinux_2_28_aarch64.whl
Size 457.9 kB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
44e332ee3b810be22cf60af5a460e9b58166032037e1e31d8451141e719d81ec
BLAKE2b-256 checksum
How to use checksums
db2af6799773468d205af7d5e4b56dabcb33b916fdaf4672ec0d17db7ebb594b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL ferronit-0.25.0-cp312-abi3-macosx_11_0_arm64.whl
Size 434.6 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4bfd730b13ad54443d5e3e4f3d50c37a86c25727fcf0a1a163789abbe86eca77
BLAKE2b-256 checksum
How to use checksums
598e783a9e2d73f0732229c6508acb69bb751efdc96a9a129ef141d8cc5868d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ferronit-0.25.0-cp312-abi3-macosx_10_12_x86_64.whl

Download URL ferronit-0.25.0-cp312-abi3-macosx_10_12_x86_64.whl
Size 444.3 kB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
303c0c2cf6e3f66d12d86ff86cf5103733ce2e42efb0f33974d4339b058a84f8
BLAKE2b-256 checksum
How to use checksums
830f2b33e2ebea158bedc1bb251f3595f88f413179c149f4c2fdff8b9d596fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for ferronit 0.25.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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