Registry / web-framework / sqladmin

sqladmin

JSON →
library0.24.0pypypi✓ verified 35d ago

SQLAdmin is a flexible and actively developed admin interface for SQLAlchemy models, designed for use with FastAPI and Starlette. It provides a UI for managing database models, leveraging WTForms for form building and Tabler for the UI. The library maintains a regular release cadence, with updates typically occurring every few weeks to a month.

web-frameworkdatabase
Install & Compatibility
Where this runs
tested against v0.27.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 1.189s · 50.6MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 4.0s · import 1.079s · 49MB
49MB installed
● package 49MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from sqladmin import Admin
from sqladmin import ModelView

AuthenticationBackend is in a submodule, not directly under sqladmin.

from sqladmin.authentication import AuthenticationBackend

This quickstart demonstrates how to integrate SQLAdmin into a FastAPI application, defining a simple SQLAlchemy model and exposing it through the admin panel. It sets up an in-memory SQLite database and registers a `UserAdmin` view.

import os from fastapi import FastAPI from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.orm import declarative_base, sessionmaker from sqladmin import Admin, ModelView # 1. Database Setup DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///./example.db") engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) Base = declarative_base() class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True) name = Column(String, default="Anonymous") email = Column(String, unique=True, nullable=False) Base.metadata.create_all(engine) # 2. FastAPI App Setup app = FastAPI(title="My SQLAdmin App") # 3. SQLAdmin Setup admin = Admin(app, engine, title="My Admin Panel") # 4. Define ModelView class UserAdmin(ModelView, model=User): column_list = [User.id, User.name, User.email] column_searchable_list = [User.name, User.email] column_sortable_list = [User.id, User.name, User.email] column_default_sort = ('id', True) # 5. Add ModelView to Admin admin.add_view(UserAdmin) @app.get("/") async def read_root(): return {"message": "Welcome! Visit /admin for the admin panel."} # To run this: # pip install fastapi uvicorn sqladmin sqlalchemy # uvicorn your_module_name:app --reload # Then navigate to http://127.0.0.1:8000/admin in your browser.
Debug
Known footguns
gotchaSQLAdmin does not include authentication by default. For production environments, you must implement a custom `AuthenticationBackend` and integrate it with your ASGI application's middleware. Failing to do so will leave your admin panel publicly accessible.
breakingThe `AuthenticationBackend.authenticate` method signature has undergone breaking changes in versions 0.10.0 and 0.12.0. Custom authentication backends developed for older versions may require updates to match the new method signature (e.g., to support OAuth or updated `Request` object access).
breakingThe internal structure for template files changed around version 0.17.0, moving default templates from the `templates/` directory to `templates/sqladmin/`. If you have custom templates that override SQLAdmin's default ones, their paths may need adjustment.
gotchaWhen working with SQLAlchemy relationships, lazy-loaded relationships can cause `DetachedInstanceError` if accessed after the SQLAlchemy session has been closed. This is a common pitfall in ORM usage, especially in web contexts where sessions are typically short-lived.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
33 hits · last 30 days
googlebot
7
chatgpt-user
5
ahrefsbot
4
oai-searchbot
4
dotbot
3
petalbot
3
script
1
bingbot
1
bytedance
1
Resources