Quickstart SQLAdmin with FastAPI
mainTo integrate SQLAdmin into a FastAPI application, initialize the Admin class with your FastAPI app instance and your SQLAlchemy engine. Define a class inheriting from ModelView, specifying the model to manage, and then register it using admin.add_view(). By default, the admin interface is available at the /admin path.
from fastapi import FastAPI
from sqladmin import Admin, ModelView
# Assuming 'engine' and 'User' model are already defined
app = FastAPI()
admin = Admin(app, engine)
class UserAdmin(ModelView, model=User):
column_list = [User.id, User.name]
admin.add_view(UserAdmin)