FastAPI-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.
Project description
Introduction
FastAPI-Amis-Admin
fastapi-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-admin
is a high-performance and efficient framework based on fastapi
& amis
with Python 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 the Apache2.0
protocol, 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.
Features
- High performance: Based on FastAPI. Enjoy all the benefits.
- High efficiency: Perfect code type hints. Higher code reusability.
- Support asynchronous and synchronous hybrid writing:
ORM
is based onSQLModel
&Sqlalchemy
. Freely customize database type. Support synchronous and asynchronous mode. Strong scalability. - Front-end separation: The front-end is rendered by
Amis
, the back-end interface is automatically generated byfastapi-amis-admin
. The interface is reusable. - Strong scalability: The background page supports
Amis
pages and ordinaryhtml
pages. Easily customize the interface freely. - Automatic api documentation: Automatically generate Interface documentation by
FastAPI
. Easily debug and share interfaces.
Dependencies
- FastAPI: Finish the web part.
- SQLModel: Finish
ORM
model mapping. Perfectly combine SQLAlchemy with Pydantic, and have all their features . - Amis: Finish admin page presentation.
Composition
fastapi-amis-admin
consists of three core modules, of which, amis
, fastapi-sqlmodel-crud
can be used as separate
modules, amis_admin
is developed by the former.
amis
: Based on thepydantic
data model building library ofbaidu amis
. To generate/parse data rapidly.fastapi-sqlmodel-crud
: Based onFastAPI
&SQLModel
. To quickly build Create, Read, Update, Delete common API interface .admin
: Inspired byDjango-Admin
. Combineamis
withfastapi-sqlmodel-crud
. To quickly build Web Admin dashboard .
Installation
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 AdminSite instance
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
ModelAdmin 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'))
# Create an SQLModel, see document for details: 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'
# set model
model = Category
# mount AdminSite instance
site.mount_app(app)
# create initial 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)
FormAdmin 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'
# set form information, optional
form = Form(title='This is a test login form', submitText='login')
# create form schema
class schema(BaseModel):
username: str = Field(..., title='username', min_length=3, max_length=30)
password: str = Field(..., title='password')
# handle 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 successfully!', data={'token': 'xxxxxx'})
return BaseApiOut(status=-1, msg='Incorrect username or password!')
# mount AdminSite instance
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Working with Command
# Install command line extension
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
# Fast running project
faa run
Preview
- Open
http://127.0.0.1:8000/admin/
in your browser:
- Open
http://127.0.0.1:8000/admin/docs
in your browser:
Project
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 managementFastAPI
extension based onAPScheduler
.FastAPI-Amis-Admin-Demo
: An exampleFastAPI-Amis-Admin
application.FastAPI-User-Auth-Demo
: An exampleFastAPI-User-Auth
application.
License
- According to the
Apache2.0
protocol,fastapi-amis-admin
is free and open source. It can be used for commercial for free, but please clearly display copyright information aboutFastAPI-Amis-Admin
on the display interface.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastapi_amis_admin-0.5.1a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c6fccee5e0e7cbe0da943bbbfb90f543de8a95238c01da350cddce0686d875 |
|
MD5 | 3321266bafe3529d740054006cf400a2 |
|
BLAKE2b-256 | 584501b41f34e8a1c11da62cf6048d9f2093e5f052d8618475242690a50ad17e |
Hashes for fastapi_amis_admin-0.5.1a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fedc3db177a7c3ee6345fa400233e86effdf6ae951c2b919185847bd2b6c037 |
|
MD5 | 3af2b10d82586e74a47a432fe3a549bd |
|
BLAKE2b-256 | ec8b2ae96e20f6315eac09396ee7ddd5fa3eb591aa30006fb7f206d39b724670 |