FastAPI-Config is a visual dynamic configuration management extension based on FastAPI-Amis-Admin.
Project description
FastAPI-Config
Project Introduction
Fast API-Config
is a visual dynamic configuration management extension package based on FastAPI-Amis-Admin
.
Install
pip install fastapi-config
Simple example
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
from typing import List
# Create a `FastAPI` application
app = FastAPI()
# Create `AdminSite` instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))
# Create a configuration repository
dbconfig = DbConfigStore(site.db)
# Register Admin (optional)
site.register_admin(ConfigModelAdmin)
class ContactCfg(BaseModel):
name: str = Field("", title="Name")
qq: List[str] = Field("", title="QQ")
class SiteCfg(BaseModel):
name: str = Field(..., title="Site Name")
logo: str = Field("", title="Site LOGO", amis_form_item=amis.InputImage())
contacts: List[ContactCfg] = Field([], title="Contact list")
domains: List[str] = Field([], title='Domain list')
class SiteCfgAdmin(ConfigAdmin):
page_schema = amis.PageSchema(label='Site Config')
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():
# Mount the site to the FastAPI instance
site.mount_app(app)
# Create database tables (required for first run)
await site.db.async_run_sync(SQLModel.metadata.create_all, is_session=False)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Interface/UI Preview
- Open
http://127.0.0.1:8000/admin/
in your browser:
Dependent project
License
The project follows the Apache2.0 license agreement.
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.1.4.tar.gz
(28.6 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_config-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 490e76c1ba395fc641081fddfd70420c1c54a9766da4a43eea9325e69c308500 |
|
MD5 | 4bf4098a37f7b2b7fc5cfebcbb272ae6 |
|
BLAKE2b-256 | 197ed64d37eef38194477d60a8b4576941dfeb8b0c0f6e43419888f84d1169f7 |