Skip to main content

FastAPI-Config is a visual dynamic configuration management extension based on FastAPI-Amis-Admin.

Project description

简体中文 | English

FastAPI-Config

Package version Downloads Chat on Gitter 229036692

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:

SchedulerAdmin

Dependent project

License

The project follows the Apache2.0 license agreement.

Project details


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)

Uploaded Source

Built Distribution

fastapi_config-0.1.4-py3-none-any.whl (37.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page