Skip to main content

Drop-in admin panel for FastAPI + SQLAlchemy + SQLModel apps

Project description

FastAPI Admin Kit

PyPI version Python versions License

A drop-in admin panel for FastAPI + SQLAlchemy apps, inspired by Django Unfold.

⚠️ Important Notice: This project is not production-ready yet. It is under active development, and the API and code may massive changes. Use it for development and testing purposes only.

📖 Documentation | 🚀 Quick Start | 📦 PyPI

Features

  • Zero-config auto-discovery of SQLAlchemy models
  • Built-in authentication, RBAC, and audit logging
  • Modern UI with Tailwind CSS, HTMX, and Alpine.js
  • Fully customizable widgets, themes, and templates
  • Inline editing from list view with 3-dot action menu
  • CLI for user management (fak-admin / fak — create superusers, list users, change passwords)
  • Async-first with support for PostgreSQL, MySQL, and SQLite

Installation

pip install fastapi-admin-kit

For database-specific async drivers:

pip install fastapi-admin-kit[postgres]  # PostgreSQL via asyncpg
pip install fastapi-admin-kit[mysql]     # MySQL via aiomysql

Quick Start

from contextlib import asynccontextmanager
from fastapi import FastAPI
from sqlalchemy import Column, Float, Integer, String
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import DeclarativeBase, relationship, sessionmaker

from fastapi_admin_kit import Admin
from fastapi_admin_kit.auth.backend import BuiltinAuthBackend
from fastapi_admin_kit.auth.mixins import AuthModelMixin
from fastapi_admin_kit.auth.models import Role, admin_user_roles


class Base(DeclarativeBase):
    pass


class User(AuthModelMixin, Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    email = Column(String(255), unique=True, nullable=False)
    full_name = Column(String(255))

    roles = relationship(
        "Role", secondary=admin_user_roles, back_populates="users"
    )


class Product(Base):
    __tablename__ = "products"
    id = Column(Integer, primary_key=True)
    name = Column(String(100), nullable=False)
    price = Column(Float, nullable=False)


DATABASE_URL = "sqlite+aiosqlite:///./app.db"
SECRET_KEY = "change-me-to-a-random-secret-key-in-production"

engine = create_async_engine(DATABASE_URL)
async_session = sessionmaker(engine, class_=AsyncSession)


@asynccontextmanager
async def lifespan(app: FastAPI):
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)
    await admin.setup()
    yield
    await engine.dispose()


app = FastAPI(lifespan=lifespan)
admin = Admin(
    app=app,
    engine=engine,
    base=Base,
    secret_key=SECRET_KEY,
    auth_model=User,
    auth_backend=BuiltinAuthBackend(),
)
admin.register(Product)

CLI Usage

Both the full name and the short alias work interchangeably:

# Create a superuser
fak-admin createsuperuser -e admin@example.com -p mypassword
fak createsuperuser -e admin@example.com -p mypassword       # short alias

# List all admin users
fak-admin users
fak users

# Change a user's password
fak-admin changepassword -e admin@example.com -p newpassword
fak changepassword -e admin@example.com -p newpassword

All commands accept -d DATABASE_URL or read the DATABASE_URL environment variable.

Configuration

Environment Variables

Variable Description Default
DATABASE_URL Async database connection string sqlite+aiosqlite:///./app.db
SECRET_KEY Signing key for sessions/CSRF/JWT (min 32 chars) Required in production

Admin Options

admin = Admin(
    app=app,
    engine=engine,
    base=Base,
    secret_key=SECRET_KEY,
    title="My Admin",           # Admin panel title
    admin_path="/admin",        # URL prefix
    dark_mode_default=False,    # Dark mode on by default
    # Theme
    theme=ThemeConfig(preset="modern", primary_color="#6366F1"),
    # Auth
    auth_backend=BuiltinAuthBackend(),
    # Environment badge
    environment_label="Production",
    environment_color="danger",
)

Database Support

  • SQLite (default, built-in via aiosqlite)
  • PostgreSQL: pip install fastapi-admin-kit[postgres] + set DATABASE_URL=postgresql+asyncpg://...
  • MySQL: pip install fastapi-admin-kit[mysql] + set DATABASE_URL=mysql+aiomysql://...

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check fastapi_admin_kit/

# Build distribution
pip install hatch
hatch build

License

MIT

Project details


Download files

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

Source Distribution

fastapi_admin_kit-0.2.0.tar.gz (200.8 kB view details)

Uploaded Source

Built Distribution

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

fastapi_admin_kit-0.2.0-py3-none-any.whl (283.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_admin_kit-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi_admin_kit-0.2.0.tar.gz
  • Upload date:
  • Size: 200.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_admin_kit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6ba0e699476b6f131b7bf9196fe72ccf9c7517be1307c6464053c213e114c62d
MD5 b2785864608ea81d8631f15abb583458
BLAKE2b-256 515b95b2904efcc3eddad277b63aba7f6b4bca6502ec396d0d7d3942b8036a80

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_admin_kit-0.2.0.tar.gz:

Publisher: release.yml on borhanst/fastapi-admin-kit

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

File details

Details for the file fastapi_admin_kit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_admin_kit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7308f2758d042049c295b6509e25a0f7e8c54c99d9c8dcabf788f4e5fc7ce7b0
MD5 aa0a6c295ffd983389a5610e17a8446d
BLAKE2b-256 089abffc58e0fe90fb85af43410701a6a41625ace9d5b67d869287445967be3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_admin_kit-0.2.0-py3-none-any.whl:

Publisher: release.yml on borhanst/fastapi-admin-kit

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