Skip to main content

Fast Admin Dashboard based on fastapi and tortoise-orm and rest-admin.

Project description

https://img.shields.io/pypi/v/fastapi-admin.svg?style=flat https://img.shields.io/github/license/long2ice/fastapi-admin

Introduction

FastAPI-admin is a admin dashboard based on fastapi and tortoise-orm and rest-admin.

FastAPI-admin provide crud feature out-of-the-box with just a few config.

Screenshots

https://github.com/long2ice/fastapi-admin/raw/master/images/login.png https://github.com/long2ice/fastapi-admin/raw/master/images/list.png https://github.com/long2ice/fastapi-admin/raw/master/images/view.png https://github.com/long2ice/fastapi-admin/raw/master/images/create.png

Quick Start

Backend

Only you should do is runing a fastapi app and mount admin app from fastapi-admin,then call init().

import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from tortoise.contrib.fastapi import register_tortoise

from fastapi_admin.factory import app as admin_app
from fastapi_admin.site import Site, Menu

TORTOISE_ORM = {
    'connections': {
        'default': 'mysql://root:123456@127.0.0.1:3306/test'
    },
    'apps': {
        'models': {
            'models': ['examples.models'],
            'default_connection': 'default',
        }
    }
}


def create_app():
    fast_app = FastAPI()

    register_tortoise(fast_app, config=TORTOISE_ORM)

    fast_app.mount('/admin', admin_app)

    admin_app.init(
        user_model='TestUser',
        admin_secret='test',
        models='examples.models',
        site=Site(
            name='FastAPI-Admin',
            logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png',
            locale='en-US',
            locale_switcher=True,
            menu=[
                Menu(
                    name='Home',
                    url='/home',
                    icon='fa fa-home',
                ),
                Menu(
                    name='Information',
                    title=True,
                    icon='fa fa-user',
                ),
                Menu(
                    name='User',
                    url='/rest/TestUser', #important,TestUser is same of the Model class TestUser and must be /rest/<Model>.
                    icon='fa fa-user',
                ),
                Menu(
                    name='Logout',
                    url='/logout',
                    icon='icon-lock',
                )
            ]
        )
    )

    fast_app.add_middleware(
        CORSMiddleware,
        allow_origins=['*'],
        allow_credentials=True,
        allow_methods=['*'],
        allow_headers=['*'],
    )

    return fast_app


app = create_app()

if __name__ == '__main__':
    uvicorn.run('main:app', port=8000, debug=True, reload=True)

Front

cp .env.development.local.example .env and modify,then just run cd front && npm run serve,more reference in rest-admin.

Features

Enum Support

When you define a enum field of tortoise-orm,like IntEnumField,you can inherit fastapi_admin.enum.EnumMixin and impl choices() method, FastAPI-admin will auto read and display and render a select widget in front.

class Status(EnumMixin, IntEnum):
    on = 1
    off = 2

    @classmethod
    def choices(cls):
        return {
            cls.on: 'ON',
            cls.off: 'OFF'
        }

Admin User Model

Inherit fastapi_admin.models.User and add you own fields,then pass in init().

class AdminUser(User):
    is_active = fields.BooleanField(default=False, description='Is Active')
    status = fields.IntEnumField(Status, description='User Status')
    created_at = fields.DatetimeField(auto_now_add=True)
    updated_at = fields.DatetimeField(auto_now=True)

Verbose Name

FastAPI-admin will auto read description defined in tortoise-orm model Field and display in front.

ForeignKeyField Support

If ForeignKeyField not passed in menu.raw_id_fields,FastAPI-admin will get all related objects and display select in front with Model.__str__.

ManyToManyField Support

FastAPI-admin will render ManyToManyField with multiple select in form edit with Model.__str__.

JSONField Render

FastAPI-admin will render JSONField with jsoneditor as beauty interface.

Search Fields

Defined menu.search_fields in menu will render a search form by fields.

Deployment

  1. Deploy fastapi app by gunicorn+uvicorn or reference https://fastapi.tiangolo.com/deployment/.

  2. Run npm run build in front dir,then copy static files in dists to you server,deployment by nginx.

ThanksTo

  • fastapi ,high performance async api framework.

  • tortoise-orm ,familiar asyncio ORM for python.

  • rest-admin,restful Admin Dashboard Based on Vue and Boostrap 4.

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-admin-0.1.6.tar.gz (12.5 kB view details)

Uploaded Source

File details

Details for the file fastapi-admin-0.1.6.tar.gz.

File metadata

  • Download URL: fastapi-admin-0.1.6.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for fastapi-admin-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a6eb632aed5d29792b170d85d7ef0b51e423ab7790b5e4bdd4e149828037b333
MD5 3269b7360adaf9d78a8686e8c123ed45
BLAKE2b-256 cd175214d6e0aa270a1058bb33f22f83e6e7a53022806576ff8109d48fe5b4fb

See more details on using hashes here.

Supported by

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