Skip to main content

FastFort

Batteries-included authentication and admin framework for FastAPI.

Django-style model registration · Professional admin UI · JWT + session auth · Roles & permissions · Audit logging · SQLAlchemy & Tortoise · No Node.js required

CI License: MIT Python

[!WARNING] Early stage. 0.1.0 is the first release and the public API is not stable yet — before 1.0, a minor release may contain breaking changes, each one listed under a Breaking heading in the changelog. Pin a version.


Why FastFort?

Every FastAPI project rebuilds the same things from scratch: an admin panel, login, refresh tokens, roles, an audit trail. Django ships all of that out of the box. FastAPI does not.

FastFort fills that gap.

uv add "fastfort[sqlalchemy]"
# main.py
from fastapi import FastAPI
from fastfort import FastFort, FastFortSettings
from fastfort.orm.sqlalchemy import SQLAlchemyBackend

from app.db import Base, session_factory
from app.models import User

app = FastAPI()

fort = FastFort(
    settings=FastFortSettings(project_name="Shop"),
    backend=SQLAlchemyBackend(session_factory=session_factory, base=Base),
)
fort.set_user_model(User, identity_field="email")
fort.autodiscover("app")
fort.mount(app)
# app/products/admin.py
from fastfort import admin

from app.models import Product


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ("id", "name", "price", "is_active", "created_at")
    list_filter = ("is_active", "category")
    search_fields = ("name", "description")
    ordering = ("-created_at",)
    select_related = ("category",)
    icon = "box"  # drawn beside the sidebar entry

    # Offered once rows are selected. "delete" is built in; this adds another.
    actions = ("delete", "archive")

    @admin.action("Archive", icon="box")
    async def archive(self, adapter, objects):
        for product in objects:
            await adapter.update(product, {"is_active": False})
        return f"{len(objects)} products archived."

Create the first account and start the server:

uv run fastfort generate-secret --export      # a signing key
FF_PASSWORD=... uv run fastfort createsuperuser \
    --identity you@example.com --password-env FF_PASSWORD --no-input
uv run uvicorn main:app

Open http://127.0.0.1:8000/admin, sign in, and you have a list, a search box, filters, sortable columns, numbered pagination, row selection with bulk actions, and working create, edit and delete pages. Foreign keys become searchable pickers -- backed by an autocomplete endpoint once the target table outgrows a dropdown -- and many-to-many fields become removable chips.

None of it needs JavaScript to work. Every control is a real form input and every sort header a real link; the browser-side code upgrades them in place and gets out of the way when it is not there.

Field names are checked against the model when the admin is built, so a typo in list_display is a start-up error naming every problem at once -- not a 500 the first time someone opens that page.


Features

🎛 Django-style admin @admin.register, list_display, list_filter, search_fields, fieldsets, actions
🗑 Deletes you can trust The confirmation counts what actually goes: rows that cascade, rows kept with the link cleared, and rows that block the delete outright — refused with a sentence instead of a constraint violation
🎨 A UI you will not want to replace Light and dark themes, brand colour from a single setting, ⌘K command palette, full keyboard navigation, real mobile layout
🔐 Production-grade auth Argon2id hashing, JWT access/refresh, token rotation with reuse detection, login lockout, CSRF protection
👥 Roles and permissions Object-level, row-level and field-level access control
📝 Audit log Who changed what and when, with an old → new diff
🗄 Three databases SQLite · PostgreSQL · MySQL, with identical behaviour
🔌 Two ORMs, one admin SQLAlchemy 2.0 and Tortoise ORM behind one adapter contract — and a conformance suite that asks both the same questions, so "the second one behaves the same" is a test rather than a claim
🧩 Every column type Text, numbers, money, dates, durations, UUIDs, JSON, hstore, arrays, enums, ranges and multiranges, inet/cidr/macaddr, bit strings — each with a real control, real validation and a filter where one makes sense. register_type adds your own
🗺 PostGIS All seven geometry kinds, drawn and edited on a hand-rolled slippy map — point, line, polygon with holes, and the multi-shapes. Spatial filters: within, intersects, and "5 km from here"
🧠 Vector search pgvector columns ranked by similarity — ?embedding__near=[…] with cosine, L2, L1 or inner product, a neighbour count and a distance bound
🌍 Eleven languages English, Uzbek, Russian, Turkish, German, French, Spanish, Chinese, Japanese, Korean and Arabic — the last of them right-to-left, which turns the whole layout around from one attribute. The catalogues ship in the package, so the admin is already translated the moment you install it — there is nothing to configure
⌨️ A CLI that matters createsuperuser so a fresh install has a way in, and check --deploy that exits non-zero
📤 Export and import The current view out as CSV, Excel or JSON — filters, search and ordering included. And back in again: the same parsers the form uses, foreign keys resolved by name or id, every bad cell reported at once with its line number, and nothing written unless the whole file parses. No openpyxl, no pandas
📦 No Node.js CSS and JavaScript ship pre-built inside the package, served Brotli-compressed with a gzip fallback — 24 KB of CSS and 29 KB of JavaScript on the wire

How it is put together

UI (Jinja2 · CSS · HTMX)   ─┐
Admin (ModelAdmin, forms)  ─┤
Auth (tokens, permissions) ─┼──►  Spec layer (immutable, JSON-serialisable)  ◄── ORM adapters
Core (settings, registry)  ─┘

Everything above the spec layer is ORM-agnostic, and that boundary is enforced by tests rather than by convention. Adding a new ORM therefore never touches the admin or the UI, and a JSON API for a future SPA front end comes for free from the same specs the templates render.


Installation

uv add "fastfort[sqlalchemy,postgres]"    # SQLAlchemy on PostgreSQL
uv add "fastfort[sqlalchemy,mysql]"       # SQLAlchemy on MySQL
uv add "fastfort[sqlalchemy,sqlite]"      # SQLAlchemy on SQLite
uv add "fastfort[tortoise,postgres]"      # Tortoise on PostgreSQL
uv add "fastfort[all]"                    # everything

Requires Python 3.11 or newer. The ORMs are separate extras and neither is imported at package level, so installing one never pulls in the other.

Tortoise instead of SQLAlchemy

Four lines differ. Everything else — the settings, @admin.register, list_display, actions, export, import — is identical, because everything else is above the ORM layer and never sees a model:

from tortoise import Tortoise
from fastfort.orm.tortoise import TortoiseBackend

await Tortoise.init(
    db_url="postgres://…",
    modules={"models": ["app.models"]},
    # Tortoise 1.1 keeps its connections in a contextvar, and an ASGI server runs
    # the lifespan in a different task from the requests. Without this flag the
    # init above is invisible to every view: start-up looks healthy and the first
    # page that touches the database is a 500. `RegisterTortoise` from
    # `tortoise.contrib.fastapi` passes it for you.
    _enable_global_fallback=True,
)

fort = FastFort(settings=FastFortSettings(...), backend=TortoiseBackend())
fort.set_user_model(User)
fort.mount(app)

Development

The only prerequisite is uv. No Node.js, ever.

uv sync --all-extras          # set up the environment
uv run pytest                 # tests (SQLite)
uv run pytest --db=all        # tests against all three databases (needs Docker)
uv run ruff check .           # linting
uv run mypy fastfort          # type checking
make check                    # every gate at once

Two scratch applications come with the repository, and they are the fastest way to see any of this working:

make sandbox              # test_api/ on PostgreSQL — every column type,
                          #   PostGIS geometry, pgvector, on :8000
make sandbox-tortoise     # test_api_tortoise/ on SQLite — a different schema,
                          #   the same admin, on :8001

Open them side by side. The models, the ORM and the database all differ; the admin does not, which is the whole of what the layering buys.

See CONTRIBUTING.md before opening a pull request, and SECURITY.md to report a vulnerability.


License

MIT © Matnazar

Download files

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

Source Distribution

fastfort-0.3.0.tar.gz (486.8 kB view details)

Uploaded Source

Built Distribution

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

fastfort-0.3.0-py3-none-any.whl (397.8 kB view details)

Uploaded Python 3

File details

Details for the file fastfort-0.3.0.tar.gz.

File metadata

  • Download URL: fastfort-0.3.0.tar.gz
  • Upload date:
  • Size: 486.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fastfort-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b47716bb001f3a00170d378041bd53cadb3ae2b07a846a2f4e6a4d32ae3a0f35
MD5 7a255a1820d96320e821386f09958f4d
BLAKE2b-256 2a4805b5c6cf54df1f854af639d26c90bd348c20fa019bf058fabeace05f4e83

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfort-0.3.0.tar.gz:

Publisher: publish.yml on Matnazar-Matnazarov/fastfort

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

File details

Details for the file fastfort-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: fastfort-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 397.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fastfort-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82cc3408d7b7f939564b39fcc9739b0e8c4b661cf374f4f9ae9425ad5cace52b
MD5 a98d19d4ead1eab0c4a215a9c1651d98
BLAKE2b-256 716f392962da467d4558cce1553bde09b08591644533f5fc53c2900f73173dac

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfort-0.3.0-py3-none-any.whl:

Publisher: publish.yml on Matnazar-Matnazarov/fastfort

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 Sentry Error logging StatusPage Status page