Skip to main content

Ferrum: A Rust-first web framework with Django-like Python API

Project description

Ferrum

Ferrum is a Django-inspired framework with a Rust runtime core and a Python developer API.

What Ferrum currently provides

  • Rust-owned HTTP runtime (axum + tokio) bridged to Python via pyo3.
  • Django-style management commands (manage.py, startproject, startapp, makemigrations, migrate, showmigrations).
  • App registry and settings boot flow via FERRUM_SETTINGS_MODULE, including apps.py discovery and ready() hooks.
  • Middleware pipeline from MIDDLEWARE (process_request, process_response, process_exception).
  • ORM foundations:
    • Models and fields (CharField, IntegerField, FloatField, BooleanField, ForeignKey, ManyToManyField)
    • QuerySet operations (get, filter, exclude, all, first, last, latest, earliest, exists, count, aggregate, values, values_list, distinct, slicing, create, update, delete, etc.)
    • Expanded lookups (__icontains, __istartswith, __iendswith, __range, __in, __isnull, comparison lookups)
    • Model lifecycle operations (save(update_fields=...), refresh_from_db(), instance delete())
    • Relation loading and traversal (select_related, prefetch_related, reverse managers, M2M manager add/remove/clear/set)
    • Transactions (atomic)
    • App-scoped table naming and migration tracking
  • Safer SQL execution defaults:
    • raw SQL runs through app table allowlist checks by default
    • explicit high-trust bypass via unsafe_unchecked=True for migration/operator workflows
  • Migration planner features:
    • cross-app dependency graph
    • cycle detection
    • target and fake application (migrate <app> <target> --fake)
    • migration metadata checksums (ferrum_migration_meta) with checksum drift detection
    • deterministic warnings for rename/removal/alter autodiff gaps
  • Backend adapter seams:
    • SQLite runtime backend
    • PostgreSQL runtime backend
    • dual-backend ORM parity tests (SQLite + PostgreSQL, PostgreSQL enabled with env)
  • Installed app governance:
    • ferrum_installed_apps sync
    • startup drift enforcement when removing apps that still have applied migrations

Quickstart (uv + maturin)

# Install Python 3.14t (free-threaded)
uv python install 3.14t

# Create virtual environment
uv venv --python 3.14t .venv
source .venv/bin/activate

# Install ferrum-rs
pip install ferrum-rs

# Or install from source
pip install -e .
pip install maturin
maturin develop

Run tests:

pytest tests/
cargo test

Test coverage:

  • Python: 132 passing tests
  • Rust: passing tests

Run PostgreSQL parity variants by setting:

export FERRUM_TEST_POSTGRES_URL="postgresql://<user>:<pass>@localhost:<port>/<db>"
pytest -q

Free-threaded Python only (no GIL)

Ferrum only supports free-threaded CPython with no GIL:

  • Python version: >=3.14
  • Build type: free-threaded (python3.14t / Py_GIL_DISABLED=1)
  • Runtime mode: gil_enabled=False

Set up with uv:

# Install Python 3.14t
uv python install 3.14t

# Create and activate venv
uv venv --python 3.14t .venv
source .venv/bin/activate

# Install from PyPI
pip install ferrum-rs

# Or install from source
pip install maturin
pip install -e .
maturin develop

Verify runtime mode:

python -c "import ferrum; print(ferrum.runtime_info())"

Expected when no-GIL is active:

  • "free_threaded_build": True
  • "gil_enabled": False
  • "no_gil_active": True

Ferrum will fail fast at import if any of the above conditions are not met. If needed, force no-GIL mode at runtime with:

PYTHON_GIL=0 python example_project/manage.py runserver 8131

Create a new project

Use ferrum-admin (script entrypoint) or call management directly.

ferrum-admin startproject mysite
cd mysite
python manage.py help

Generated structure:

mysite/
├── manage.py
└── mysite/
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    ├── asgi.py
    └── wsgi.py

Create an app

python manage.py startapp books

This creates:

  • books/models.py
  • books/apps.py
  • books/views.py
  • books/urls.py
  • books/migrations/

and appends "books" to INSTALLED_APPS.

Re-running startapp books is idempotent and repairs missing scaffold files.

Migrations workflow

python manage.py makemigrations
python manage.py showmigrations
python manage.py migrate

Targeted and fake migration examples:

python manage.py migrate books 0001_initial --fake
python manage.py migrate books 0002_more

Middleware configuration

In settings.py:

MIDDLEWARE = [
    "myproject.middleware.TraceHeaderMiddleware",
    "myproject.middleware.ValueErrorMiddleware",
]

Supported hooks on middleware classes:

  • process_request(self, request) -> HttpResponse | None
  • process_response(self, request, response) -> HttpResponse
  • process_exception(self, request, exc) -> HttpResponse | None

Run server

Default:

python manage.py runserver
  • Uses PORT from settings when not passed explicitly.
  • You can override with a CLI port: python manage.py runserver 9000.
  • Enable stat autoreload in development: python manage.py runserver --reload.

Model lifecycle helpers

book = Book.objects.create(title="Before", pages=100)
book.title = "After"
book.save(update_fields=["title"])
book.refresh_from_db()
book.delete()

Example project in this repo

Reference implementation is in:

  • example_project/manage.py
  • example_project/example_project/settings.py
  • example_project/example_project/urls.py
  • example_project/demo_app/models.py
  • example_project/demo_app/views.py
  • example_project/demo_app/urls.py

Try:

# From the ferrum-rs source directory
python example_project/manage.py makemigrations demo_app --name initial
python example_project/manage.py migrate
python example_project/manage.py runserver 8131

Then:

curl -i http://127.0.0.1:8131/books/
curl -i -X POST http://127.0.0.1:8131/books/create/
curl -i http://127.0.0.1:8131/books/1
curl -i -X POST http://127.0.0.1:8131/relationships/seed/
curl -i http://127.0.0.1:8131/books/1/graph/
curl -i http://127.0.0.1:8131/books/1/buyers/
curl -i http://127.0.0.1:8131/buyers/1/books/
curl -i http://127.0.0.1:8131/books/queryset/
curl -i -X POST http://127.0.0.1:8131/books/lifecycle-demo/
curl -i http://127.0.0.1:8131/middleware/42/?q=rust
curl -i http://127.0.0.1:8131/middleware/error/

Roadmap

Roadmap and milestone tracking live in:

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

ferrum_rs-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

File details

Details for the file ferrum_rs-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ferrum_rs-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4e572bd473a0af198af5127d24b868a90f6900fc5bfcfa2350f0f0d2019333b
MD5 758a170f9d71b3cbacee45b497c6d5c4
BLAKE2b-256 52982458f4bd68828f74a8fac9a9b42a50ed1aa98f71df11e8cc82c5c107b8d4

See more details on using hashes here.

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