Package: fastapi_amis_admin
简体中文|EnglishIntroductionFastAPI-Amis-Adminfastapi-amis-admin is a high-performance, efficient and easily extensible FastAPI admin framework.Inspired by Django-admin, and has as many powerful functions as Django-admin.source code·online demo·documentation·can't open the document?fastapi-amis-adminis a high-performance and efficient framework based onfastapi&amiswithPython 3.7+, and
based on standard Python type hints. The original intention of the development is to improve the application ecology and
to quickly generate a visual dashboard for the web application . According to theApache2.0protocol, it is free and
open source . But in order to better operate and maintain this project in the long run, I very much hope to get
everyone's sponsorship and support.FeaturesHigh performance: Based onFastAPI. Enjoy all the benefits.High efficiency: Perfect code type hints. Higher code reusability.Support asynchronous and synchronous hybrid writing:ORMis based onSQLModel&Sqlalchemy. Freely customize
database type. Support synchronous and asynchronous mode. Strong scalability.Front-end separation: The front-end is rendered byAmis, the back-end interface is automatically generated
byfastapi-amis-admin. The interface is reusable.Strong scalability: The background page supportsAmispages and ordinaryhtmlpages. Easily customize the
interface freely.Automatic api documentation: Automatically generate Interface documentation byFastAPI. Easily debug and share
interfaces.DependenciesFastAPI: Finish the web part.SQLModel: FinishORMmodel mapping. Perfectly
combineSQLAlchemywithPydantic, and have all
their features .Amis: Finish admin page presentation.Compositionfastapi-amis-adminconsists of three core modules, of which,amis,crudcan be used as separate
modules,adminis developed by the former.amis: Based on thepydanticdata model building library ofbaidu amis. To generate/parse data rapidly.crud: Based onFastAPI&Sqlalchemy. To quickly build Create, Read, Update, Delete common API
interface .admin: Inspired byDjango-Admin. Combineamiswithcrud. To quickly build Web Admin
dashboard .Installationpipinstallfastapi_amis_adminNotesqlmodelcurrently does not supportsqlalchemy 2.0+. If you usesqlalchemy 2.0+to create a model, you cannot
usesqlmodelat the same time.After versionfastapi-amis-admin>=0.6.0,sqlmodelis no longer a required dependency library. If you usesqlmodelto create a model, you can install it with the following command.pipinstallfastapi_amis_admin[sqlmodel]Simple ExamplefromfastapiimportFastAPIfromfastapi_amis_admin.admin.settingsimportSettingsfromfastapi_amis_admin.admin.siteimportAdminSite# create FastAPI applicationapp=FastAPI()# create AdminSite instancesite=AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))# mount AdminSite instancesite.mount_app(app)if__name__=='__main__':importuvicornuvicorn.run(app)ModelAdmin ExampleCreate ModelSupportSQLModelmodel,SQLAlchemymodel,SQLAlchemy 2.0modelMethod 1: Create model throughSQLModel.fromtypingimportOptionalfromsqlmodelimportSQLModelfromfastapi_amis_admin.models.fieldsimportFieldclassBase(SQLModel):pass# Create an SQLModel, see document for details: https://sqlmodel.tiangolo.com/classCategory(SQLModel,table=True):id:Optional[int]=Field(default=None,primary_key=True,nullable=False)name:str=Field(title='CategoryName',max_length=100,unique=True,index=True,nullable=False)description:str=Field(default='',title='Description',max_length=255)Method 2: Create model throughSQLAlchemy.fromsqlalchemyimportColumn,Integer,Stringfromsqlalchemy.ext.declarativeimportdeclarative_baseBase=declarative_base()# Create an SQLAlchemy model, see document for details: https://docs.sqlalchemy.org/en/14/orm/tutorial.htmlclassCategory(Base):__tablename__='category'# Specify the Schema class corresponding to the model. It is recommended to specify it. If omitted, it can be automatically generated.__pydantic_model__=CategorySchemaid=Column(Integer,primary_key=True,nullable=False)name=Column(String(100),unique=True,index=True,nullable=False)description=Column(String(255),default='')Method 3: Create model throughSQLAlchemy 2.0.fromsqlalchemyimportStringfromsqlalchemy.ormimportDeclarativeBase,Mapped,mapped_columnclassBase(DeclarativeBase):pass# Create an SQLAlchemy 2.0 model, see document for details: https://docs.sqlalchemy.org/en/20/orm/quickstart.htmlclassCategory(Base):__tablename__="category"# Specify the Schema class corresponding to the model. It is recommended to specify it. If omitted, it can be automatically generated.__pydantic_model__=CategorySchemaid:Mapped[int]=mapped_column(primary_key=True,nullable=False)name:Mapped[str]=mapped_column(String(100),unique=True,index=True,nullable=False)description:Mapped[str]=mapped_column(String(255),default="")If you create a model throughsqlalchemy, it is recommended to create a corresponding pydantic model at the same
time, and setorm_mode=True.frompydanticimportBaseModel,FieldclassCategorySchema(BaseModel):id:Optional[int]=Field(default=None,primary_key=True,nullable=False)name:str=Field(title="CategoryName")description:str=Field(default="",title="CategoryDescription")classConfig:orm_mode=TrueRegister ModelAdminfromfastapiimportFastAPIfromfastapi_amis_admin.admin.settingsimportSettingsfromfastapi_amis_admin.admin.siteimportAdminSitefromfastapi_amis_admin.adminimportadmin# create FastAPI applicationapp=FastAPI()# create AdminSite instancesite=AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))# register ModelAdmin@site.register_adminclassCategoryAdmin(admin.ModelAdmin):page_schema='Category'# set modelmodel=Category# mount AdminSite instancesite.mount_app(app)# create initial database table@app.on_event("startup")asyncdefstartup():awaitsite.db.async_run_sync(Base.metadata.create_all,is_session=False)if__name__=='__main__':importuvicornuvicorn.run(app)FormAdmin ExamplefromtypingimportAnyfromfastapiimportFastAPIfrompydanticimportBaseModelfromstarlette.requestsimportRequestfromfastapi_amis_admin.amis.componentsimportFormfromfastapi_amis_admin.adminimportadminfromfastapi_amis_admin.admin.settingsimportSettingsfromfastapi_amis_admin.admin.siteimportAdminSitefromfastapi_amis_admin.crud.schemaimportBaseApiOutfromfastapi_amis_admin.models.fieldsimportField# create FastAPI applicationapp=FastAPI()# create AdminSite instancesite=AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))# register FormAdmin@site.register_adminclassUserLoginFormAdmin(admin.FormAdmin):page_schema='UserLoginForm'# set form information, optionalform=Form(title='This is a test login form',submitText='login')# create form schemaclassschema(BaseModel):username:str=Field(...,title='username',min_length=3,max_length=30)password:str=Field(...,title='password')# handle form submission dataasyncdefhandle(self,request:Request,data:BaseModel,**kwargs)->BaseApiOut[Any]:ifdata.username=='amisadmin'anddata.password=='amisadmin':returnBaseApiOut(msg='Login successfully!',data={'token':'xxxxxx'})returnBaseApiOut(status=-1,msg='Incorrect username or password!')# mount AdminSite instancesite.mount_app(app)if__name__=='__main__':importuvicornuvicorn.run(app)Working with Command# Install command line extensionpipinstallfastapi_amis_admin[cli]# View helpfaa--help# Initialize a `FastAPI-Amis-Admin` projectfaanewproject_name--init# Initialize a `FastAPI-Amis-Admin` applicationfaanewapp_name# Fast running projectfaarunPreviewOpenhttp://127.0.0.1:8000/admin/in your browser:Openhttp://127.0.0.1:8000/admin/docsin your browser:ProjectAmis-Admin-Theme-Editor:Theme-Editor for the fastapi-amis-admin.
Allows to add custom css styles and to apply theme --vars change on the fly.FastAPI-User-Auth: A simple and powerfulFastAPIuserRBACauthentication and authorization library.FastAPI-Scheduler: A simple scheduled task managementFastAPIextension
based onAPScheduler.FastAPI-Config: A visual dynamic configuration management extension package
based onFastAPI-Amis-Admin.FastAPI-Amis-Admin-Demo: An exampleFastAPI-Amis-Adminapplication.FastAPI-User-Auth-Demo: An exampleFastAPI-User-Authapplication.LicenseAccording to theApache2.0protocol,fastapi-amis-adminis free and open source. It can be used for commercial for
free, but please clearly display copyright information aboutFastAPI-Amis-Adminon the display interface.