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 viapyo3. - Django-style management commands (
manage.py,startproject,startapp,makemigrations,migrate,showmigrations). - App registry and settings boot flow via
FERRUM_SETTINGS_MODULE, includingapps.pydiscovery andready()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(), instancedelete()) - Relation loading and traversal (
select_related,prefetch_related, reverse managers, M2M manageradd/remove/clear/set) - Transactions (
atomic) - App-scoped table naming and migration tracking
- Models and fields (
- Safer SQL execution defaults:
- raw SQL runs through app table allowlist checks by default
- explicit high-trust bypass via
unsafe_unchecked=Truefor 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_appssync- 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.pybooks/apps.pybooks/views.pybooks/urls.pybooks/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 | Noneprocess_response(self, request, response) -> HttpResponseprocess_exception(self, request, exc) -> HttpResponse | None
Run server
Default:
python manage.py runserver
- Uses
PORTfrom 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.pyexample_project/example_project/settings.pyexample_project/example_project/urls.pyexample_project/demo_app/models.pyexample_project/demo_app/views.pyexample_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ferrum_rs-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl.
File metadata
- Download URL: ferrum_rs-0.1.1-cp314-cp314t-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.14t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4e572bd473a0af198af5127d24b868a90f6900fc5bfcfa2350f0f0d2019333b
|
|
| MD5 |
758a170f9d71b3cbacee45b497c6d5c4
|
|
| BLAKE2b-256 |
52982458f4bd68828f74a8fac9a9b42a50ed1aa98f71df11e8cc82c5c107b8d4
|