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.
pip install sqladminVerified import paths — ran on the pinned version, not inferred.
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.
Implement a custom `AuthenticationBackend` by inheriting `sqladmin.authentication.AuthenticationBackend` and configure your ASGI app with an appropriate authentication middleware (e.g., Starlette's `AuthenticationMiddleware`). Refer to the official documentation for examples.
Review your custom `AuthenticationBackend` implementation and update the `authenticate` method signature and logic to align with the changes introduced in the respective versions. Consult the `CHANGELOG.md` or official documentation for the exact signature updates.
Ensure your custom template files are placed within a `templates/sqladmin/` directory in your project's root or a configured template search path. If you previously referred to `some_template.html`, you might now need to refer to `sqladmin/some_template.html` if overriding.
To prevent `DetachedInstanceError`, explicitly eager-load relationships using `selectinload` or include the related columns in `ModelView.column_list` or `ModelView.column_details_list` so that SQLAdmin fetches them within the active session. Ensure your `get_session` method manages the session lifecycle correctly.
Ensure that the class passed to ModelView inherits from a SQLAlchemy declarative base (e.g., your Base class or SQLAlchemyBaseUserMixin).
Verify that your database server is running, check the connection string (DSN) for accuracy (host, port, user, password, database name), and confirm no firewall is blocking the connection.
Import `AdminAuth` from the `sqladmin.authentication` submodule.
Ensure you `await` any asynchronous function calls (like `create_async_engine`) where their result is needed, especially when initializing the SQLAlchemy engine for SQLAdmin.
Use the correct method for registering SQLAlchemy models, which is `admin.add_view()` with a `ModelView` instance.