Project Introduction¶
FastAPI-Amis-Admin
fastapi-amis-admin is a fastapi management background framework with high performance, high efficiency and easy expansion
Inspired by Django-Admin, and has powerful functions not inferior to Django-Admin.
Source code · Online demo · 文档 · Can't open the document?
fastapi-amis-admin
is a high-performance and efficient web-admin
framework developed based on fastapi
+amis
, using Python 3.7+ and based on standard Python type hints.
The original intention of fastapi-amis-admin
is to improve the fastapi
application ecology and quickly generate a visual management background for the fastapi
web application.
key features¶
-
High performance: Based on FastAPI, you can enjoy all the advantages of
FastAPI
. -
Faster efficiency: Perfect coding type hints, code reusability is higher.
-
Support asynchronous and synchronous mixed writing:
ORM
is based onSQLModel
+Sqlalchemy
, can customize the database type freely, supports synchronous and asynchronous mode, and has strong scalability. -
Separation of front-end and back-end: The front-end is rendered by
Amis
, the back-end interface is automatically generated byfastapi-amis-admin
, and the interface can be reused. -
Strong scalability: The background page supports
Amis
page and ordinaryhtml
page, and developers can easily customize the interface freely. -
Automatically generate API documentation: The interface documentation is automatically generated by
FastAPI
, which is convenient for developers to debug and share the interface.
core dependencies¶
- FastAPI responsible for the web part
- SQLModel Responsible for ORM model mapping (
Perfect combination of SQLAlchemy+Pydantic, with
SQLAlchemy
and all features ofPydantic
) - Amis Responsible for Admin background page display
Project composition¶
fastapi-amis-admin
consists of three core modules, of which amis
, fastapi-sqlmodel-crud
can be used as independent modules, and amis_admin
is built based on the former.
amis
:pydantic
data model building library based onbaidu amis
for fast generation/parsing ofamis
json
data.fastapi-sqlmodel-crud
: Based onFastAPI
+SQLModel
, it is used to quickly build Create, Read, Update, Delete common API interfaces.admin
: Inspired byDjango-Admin
, combined withamis
+fastapi-sqlmodel-crud
, used to quickly buildWeb Admin
management background.
Install¶
pip install fastapi_amis_admin
Simple example¶
from fastapi import FastAPI
from fastapi_amis_admin.admin.settings import Settings
from fastapi_amis_admin.admin.site import AdminSite
# Create FastAPI application
app = FastAPI()
# Create AdminSite instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))
# Mount the background management system
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Model management example¶
from fastapi import FastAPI
from sqlmodel import SQLModel
from fastapi_amis_admin.admin.settings import Settings
from fastapi_amis_admin.admin.site import AdminSite
from fastapi_amis_admin.admin import admin
from fastapi_amis_admin.models.fields import Field
# Create FastAPI application
app = FastAPI()
# Create AdminSite instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))
# First create a SQLModel model, please refer to: https://sqlmodel.tiangolo.com/
class Category(SQLModel, table=True):
id: int = Field(default=None, primary_key=True, nullable=False)
name: str = Field(title='CategoryName')
description: str = Field(default='', title='Description')
# Register ModelAdmin
@site.register_admin
class CategoryAdmin(admin.ModelAdmin):
page_schema = 'Category Management'
# Configuration management model
model = Category
# Mount the background management system
site.mount_app(app)
# Create initialized database table
@app.on_event("startup")
async def startup():
await site.db.async_run_sync(SQLModel.metadata.create_all, is_session=False)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Form management example¶
from typing import Any
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.requests import Request
from fastapi_amis_admin.amis.components import Form
from fastapi_amis_admin.admin import admin
from fastapi_amis_admin.admin.settings import Settings
from fastapi_amis_admin.admin.site import AdminSite
from fastapi_amis_admin.crud.schema import BaseApiOut
from fastapi_amis_admin.models.fields import Field
# Create FastAPI application
app = FastAPI()
# Create AdminSite instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))
# Register FormAdmin
@site.register_admin
class UserLoginFormAdmin(admin.FormAdmin):
page_schema = 'UserLoginForm'
# Configure form information, can be omitted
form = Form(title='This is a test login form', submitText='Login')
# Create form data model
class schema(BaseModel):
username: str = Field(..., title='username', min_length=3, max_length=30)
password: str = Field(..., title='password')
# Process form submission data
async def handle(self, request: Request, data: BaseModel, **kwargs) -> BaseApiOut[Any]:
if data.username == 'amisadmin' and data.password == 'amisadmin':
return BaseApiOut(msg='Login successful!', data={'token': 'xxxxxx'})
return BaseApiOut(status=-1, msg='username or password is wrong!')
# Mount the background management system
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Using the command line¶
# Install command line extensions
pip install fastapi_amis_admin[cli]
# view help
faa --help
# Initialize a `FastAPI-Amis-Admin` project
faa new project_name --init
# Initialize a `FastAPI-Amis-Admin` application
faa new app_name
# quickly run the project
It's true
Interface preview¶
- Open
http://127.0.0.1:8000/admin/
in your browser:
- Open
http://127.0.0.1:8000/admin/docs
in your browser:
Related Items¶
Amis-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 powerfulFastAPI
userRBAC
authentication and authorization library.FastAPI-Scheduler
: A simple scheduled task management project based onFastAPI
+APScheduler
.FastAPI-Amis-Admin-Demo
: A sampleFastAPI-Amis-Admin
application.FastAPI-User-Auth-Demo
: A sampleFastAPI-User-Auth
application.
agreement¶
fastapi-amis-admin
is based onApache2.0
open source and free to use, and can be used for commercial purposes for free, but please clearly display the copyright information about FastAPI-Amis-Admin in the display interface.
Thanks¶
Thanks to the following developers for their contributions to FastAPI-Amis-Admin: