FastAPI-Config is a visual dynamic configuration management extension based on FastAPI-Amis-Admin.
Project description
FastAPI-Config
项目介绍
FastAPI-Config
是一个基于FastAPI-Amis-Admin
的可视化动态配置管理拓展包.
安装
pip install fastapi-config
简单示例
main.py:
from fastapi import FastAPI
from fastapi_amis_admin import amis
from fastapi_amis_admin.admin import Settings, AdminSite
from fastapi_amis_admin.models import Field
from fastapi_config import ConfigModelAdmin, DbConfigStore, ConfigAdmin
from sqlmodel import SQLModel
from pydantic import BaseModel
# 创建`FastAPI`应用
app = FastAPI()
# 创建`AdminSite`实例
site = AdminSite(settings = Settings(database_url_async = 'sqlite+aiosqlite:///amisadmin.db'))
# 创建配置存储库
dbconfig = DbConfigStore(site.db)
# 注册管理页面(可选)
site.register_admin(ConfigModelAdmin)
class SiteCfg(BaseModel):
name: str = Field(..., title = '网站名称')
logo: str = Field('', title = '网站LOGO', amis_form_item = amis.InputImage())
class SiteCfgAdmin(ConfigAdmin):
page_schema = amis.PageSchema(label = '站点信息')
schema = SiteCfg
site.register_admin(SiteCfgAdmin)
@app.get('/config')
async def read_config():
return await dbconfig.get(SiteCfg)
@app.on_event("startup")
async def startup():
await site.db.async_run_sync(SQLModel.metadata.create_all, is_session = False)
# 挂载后台管理系统
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug = True)
界面预览
- Open
http://127.0.0.1:8000/admin/
in your browser:
依赖项目
许可协议
该项目遵循 Apache2.0 许可协议。
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
fastapi-config-0.0.2.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_config-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7669c643dc07bbd9114a528f574c1d82cf8a87bc7fb166d7a287662b48542ef |
|
MD5 | 5b6f1c59bb43c50b3d782836b395e48d |
|
BLAKE2b-256 | dbf0dff5573ae370591c8d088a486244b858a346f05e321fbb7da6a2a255cb32 |