FastAPI Admin Dashboard based on FastAPI and Tortoise ORM.

Overview

FastAPI ADMIN

image image image image

中文文档

Introduction

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

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

Live Demo

Check a live Demo here https://fastapi-admin.long2ice.cn.

  • username: admin
  • password: 123456

Data in database will restore every day.

Screenshots

image

image

image

image

Requirements

  • FastAPI framework as your backend framework.
  • Tortoise-ORM as your orm framework, by the way, which is best asyncio orm so far and I'm one of the contributors 😋 .

Quick Start

Run Backend

Look full example at examples.

  1. git clone https://github.com/long2ice/fastapi-admin.git.
  2. docker-compose up -d --build.
  3. docker-compose exec -T mysql mysql -uroot -p123456 < examples/example.sql fastapi-admin.
  4. That's just all, api server is listen at http://127.0.0.1:8000 now.

Run Front

See restful-admin for reference.

Backend Integration

> pip3 install fastapi-admin
from fastapi_admin.factory import app as admin_app

fast_app = FastAPI()

register_tortoise(fast_app, config=TORTOISE_ORM, generate_schemas=True)

fast_app.mount('/admin', admin_app)

@fast_app.on_event('startup')
async def startup():
    await admin_app.init(
        admin_secret="test",
        permission=True,
        site=Site(
            name="FastAPI-Admin DEMO",
            login_footer="FASTAPI ADMIN - FastAPI Admin Dashboard",
            login_description="FastAPI Admin Dashboard",
            locale="en-US",
            locale_switcher=True,
            theme_switcher=True,
        ),
    )

Documentation

See documentation at https://long2ice.github.io/fastapi-admin.

Deployment

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

Restful API Docs

See restful api docs.

Support this project

AliPay WeChatPay PayPal
PayPal to my account long2ice.

License

This project is licensed under the Apache-2.0 License.

Comments
  • admin/login POST does not work

    admin/login POST does not work

    Hello, nice project and thanks for sharing. I have successfully deployed and it seems everything is working. I can use the followig command:

    curl -X GET "http://192.168.1.75:8000/admin/site" -H "accept: application/json"

    and get a proper result. But if I use the following:

    curl -X POST "http://192.168.1.75:8000/admin/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"username\":\"marco\",\"password\":\"123456\"}"

    I am getting:

    {"msg":"Not Found"}

    which I don't think it is correct. In docker container "fastapi-admin" logs I am finding:

    INFO: 192.168.1.111:41788 - "POST /admin/login HTTP/1.1" 404 Not Found

    opened by mg64ve 13
  • facing issue in running docker

    facing issue in running docker

    Dear Sir,

    File "uvloop/loop.pyx", line 1994, in uvloop.loop.Loop.create_connection app_1 | ConnectionRefusedError: [Errno 111] Connection refused app_1 | app_1 | ERROR: Application startup failed. Exiting. app_1 | INFO: Started server process [1] app_1 | INFO: Waiting for application startup. app_1 | ERROR: Traceback (most recent call last): app_1 | File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 526, in lifespan app_1 | async for item in self.lifespan_context(app): app_1 | File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 467, in default_lifespan app_1 | await self.startup() app_1 | File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 502, in startup app_1 | await handler() app_1 | File "./examples/main.py", line 34, in startup app_1 | redis = await aioredis.create_redis_pool("redis://localhost", encoding="utf8") app_1 | File "/usr/local/lib/python3.9/site-packages/aioredis/commands/init.py", line 188, in create_redis_pool app_1 | pool = await create_pool(address, db=db, app_1 | File "/usr/local/lib/python3.9/site-packages/aioredis/pool.py", line 58, in create_pool app_1 | await pool._fill_free(override_min=False) app_1 | File "/usr/local/lib/python3.9/site-packages/aioredis/pool.py", line 383, in _fill_free app_1 | conn = await self._create_new_connection(self._address) app_1 | File "/usr/local/lib/python3.9/site-packages/aioredis/connection.py", line 111, in create_connection app_1 | reader, writer = await asyncio.wait_for(open_connection( app_1 | File "/usr/local/lib/python3.9/asyncio/tasks.py", line 442, in wait_for app_1 | return await fut app_1 | File "/usr/local/lib/python3.9/site-packages/aioredis/stream.py", line 23, in open_connection app_1 | transport, _ = await get_event_loop().create_connection( app_1 | File "uvloop/loop.pyx", line 2017, in create_connection app_1 | File "uvloop/loop.pyx", line 1994, in uvloop.loop.Loop.create_connection app_1 | ConnectionRefusedError: [Errno 111] Connection refused app_1 | app_1 | ERROR: Application startup failed. Exiting. fastapi-admin_app_1 exited with code 0 (testpy3.9) [email protected]:~/Python-3.9.1/fastapi-admin$ sudo docker-comp

    opened by pvssrikanth 12
  • Example - 404 Error

    Example - 404 Error

    Hi, before integrating your solution into my project, I tried to execute your example :

    image

    The application start well :

    image

    And the data are injected into the database :

    image

    But when I try to navigate to 127.0.0.1:8000/admin, I have an 404 error :

    image

    image

    Otherwise, 127.0.0.1:8000/admin/docs works

    My configuration :

    • os: Ubuntu 18.04
    • docker: 19.03.13
    • docker-compose: 1.26.0

    If you need more informations, do not hesitate to ask me.

    Thank you !

    opened by AlexTheByte 12
  • No values were fetched for this relation

    No values were fetched for this relation

    Hello! I'm using FastApi Admin. It works fine, but in one case I've got a problem. I have ManyToMany Relation in Admin section I can create and delete data, but I can't update data because this error: raise NoValuesFetched( tortoise.exceptions.NoValuesFetched: No values were fetched for this relation, first use .fetch_related())

    Resource: class PageResource(resources.Model): label = "Page" model = Page fields = [ "id", "content", Field(name="type_id", label="Page type", input_=inputs.ForeignKey(model=PageType), ), Field(name="user_id", label="User", input_=inputs.ForeignKey(model=User), ), Field(name="audios", label="Audio", display=displays.InputOnly(), input_=inputs.ManyToMany(model=Audio), ), Field(name="videos", label="Video", display=displays.InputOnly(), input_=inputs.ManyToMany(model=Video), ), ]

    class: class Page(models.Model): """ The Page model """ id = fields.BigIntField(pk=True) content = fields.TextField(null=False) user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField( "models.User", related_name="pages", on_delete=fields.CASCADE) type: fields.ForeignKeyRelation[PageType] = fields.ForeignKeyField( "models.PageType", related_name="pages", on_delete=fields.CASCADE)

    videos: fields.ManyToManyRelation[Video] = fields.ManyToManyField(
        "models.Video", related_name="pages", forward_key="video_id", backward_key="page_id",
        through="page_video"
    )
    
    audios: fields.ManyToManyRelation[Audio] = fields.ManyToManyField(
        "models.Audio", related_name="pages", forward_key="audio_id", backward_key="page_id",
        through="page_audio"
    )
    

    Please help me to manage this problem!

    opened by SantitoSB 9
  • PK values only integer

    PK values only integer

    Hi! It's me again))

    Could you please replace type annotation for pk path params in the admin routes with Union[int, UUID]?

    It would allow to use UUID type for primary keys.

    opened by Addovej 8
  • 修改用户时间问题

    修改用户时间问题

    修改用户信息的时候,时间字段出现错误。 tortoise.exceptions.OperationalError: (1292, "Incorrect datetime value: '2021-01-13T00:00:00+00:00' for column 'last_login' at row 1")

    opened by cuiwanjun 7
  • HTTP error 404 while being unauthorized

    HTTP error 404 while being unauthorized

    Hello,

    It is a bit confusing in example app to obtain 404 instead of 401 while not being authorized. Wouldn't it be more correct to return 401 error here: https://github.com/fastapi-admin/fastapi-admin/blob/master/fastapi_admin/depends.py#L73-L73 ?

    opened by radiophysicist 5
  • 本地启动examble报错:/bin/sh -c mkdir -p /fastapi-admin

    本地启动examble报错:/bin/sh -c mkdir -p /fastapi-admin

    ERROR: Service 'app' failed to build: The command '/bin/sh -c mkdir -p /fastapi-admin' returned a non-zero code: 1 抛开权限不说,这里既然用了-c是不是应该把后面的mkdir及其参数用引号包裹起来? /bin/sh -c 'mkdir -p /fastapi-admin' 我该如何修改启动脚本?

    权限问题,我手动创建了/fastapi-admin,并把文件夹属主改为了当前用户

    opened by xflcx1991 5
  • admin app not loading properly

    admin app not loading properly

    When using the sample code, /admin returns 404.

    Here's my main.py:

    from fastapi import FastAPI
    from fastapi_admin.factory import app as admin_app
    from fastapi_admin.site import Site
    from starlette.middleware.cors import CORSMiddleware
    from tortoise.contrib.fastapi import register_tortoise
    
    app = FastAPI()
    
    
    @app.get("/")
    async def root():
        return {"message": "Hello World"}
    
    app.add_middleware(
            CORSMiddleware,
            allow_origins=["*"],
            allow_credentials=True,
            allow_methods=["*"],
            allow_headers=["*"],
            expose_headers=["*"],
        )
    register_tortoise(
        app,
        db_url="sqlite://:memory:",
        modules={"models": ["database.models"]},
        generate_schemas=True,
        add_exception_handlers=True,
    )
    
    app.mount("/admin", admin_app)
    
    @app.on_event('startup')
    async def startup():
        await admin_app.init(
            admin_secret="test",
            site=Site(
                name="FastAPI-Admin DEMO",
                login_footer="FASTAPI ADMIN - FastAPI Admin Dashboard",
                login_description="FastAPI Admin Dashboard",
                locale="en-US",
                locale_switcher=True,
                theme_switcher=True,
            ),
        )
    

    Here's my requirements.txt:

    aiomysql==0.0.21
    aiosqlite==0.16.0
    asyncpg==0.22.0
    bcrypt==3.2.0
    cffi==1.14.5
    click==7.1.2
    colorama==0.4.4
    fastapi==0.63.0
    fastapi-admin==0.3.3
    gunicorn==20.1.0
    h11==0.12.0
    iso8601==0.1.14
    Jinja2==2.11.3
    MarkupSafe==1.1.1
    passlib==1.7.4
    prompt-toolkit==3.0.18
    pycparser==2.20
    pydantic==1.8.1
    PyJWT==2.1.0
    PyMySQL==0.9.3
    pypika-tortoise==0.1.0
    python-dotenv==0.17.1
    python-rapidjson==1.0
    pytz==2020.5
    six==1.15.0
    starlette==0.13.6
    tortoise-orm==0.17.2
    typing-extensions==3.10.0.0
    uvicorn==0.13.4
    wcwidth==0.2.5
    XlsxWriter==1.4.0
    
    
    opened by aminalaee 5
  • 401 Unauthorized on Frontend Part

    401 Unauthorized on Frontend Part

    I've integrated backend part +- successfully - I have nothing on /admin/, getting 404, but have created first Admin user and logged in on the backend site properly. The problem is that I'm typing the same password on frontend part and getting Unauthorized response despite the fact the credentials are correct. Here is logs I'm receiving on backend part:

    INFO:     127.0.0.1:46580 - "OPTIONS /admin/site HTTP/1.1" 200 OK
    INFO:     127.0.0.1:46580 - "GET /admin/site HTTP/1.1" 404 Not Found
    INFO:     127.0.0.1:46586 - "OPTIONS /admin/login HTTP/1.1" 200 OK
    INFO:     127.0.0.1:46586 - "POST /admin/login HTTP/1.1" 401 Unauthorized
    

    How to overcome that? Maybe I'm doing something wrong? Did I miss something? The total process of my installation is like that:

    1. Mounted to existing project - I've added admin model and some models of my apps. Database integration succeed, as well as redis integration. And the creation of the initial user was succeed. I could even login through /admin/login page - but on /admin/ I see only 404 page.
    2. Restful-admin frontend part - I've installed it using yarn and it works good, could even communicate to backend.
    opened by ftelnov 4
  • Admin login redis set() got an unexpected keyword argument 'expire'

    Admin login redis set() got an unexpected keyword argument 'expire'

    // providers/login.py
    // await redis.set(constants.LOGIN_USER.format(token=token), admin.pk, expire=expire)
    TypeError: set() got an unexpected keyword argument 'expire'
    
    opened by Pkittipat 4
  • Bump setuptools from 65.3.0 to 65.5.1

    Bump setuptools from 65.3.0 to 65.5.1

    Bumps setuptools from 65.3.0 to 65.5.1.

    Changelog

    Sourced from setuptools's changelog.

    v65.5.1

    Misc ^^^^

    • #3638: Drop a test dependency on the mock package, always use :external+python:py:mod:unittest.mock -- by :user:hroncok
    • #3659: Fixed REDoS vector in package_index.

    v65.5.0

    Changes ^^^^^^^

    • #3624: Fixed editable install for multi-module/no-package src-layout projects.
    • #3626: Minor refactorings to support distutils using stdlib logging module.

    Documentation changes ^^^^^^^^^^^^^^^^^^^^^

    • #3419: Updated the example version numbers to be compliant with PEP-440 on the "Specifying Your Project’s Version" page of the user guide.

    Misc ^^^^

    • #3569: Improved information about conflicting entries in the current working directory and editable install (in documentation and as an informational warning).
    • #3576: Updated version of validate_pyproject.

    v65.4.1

    Misc ^^^^

    v65.4.0

    Changes ^^^^^^^

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Tabler UI not working?

    Tabler UI not working?

    I have integrated the admin into my project. I was able to create first admin user with /admin/init and see the admin user in the database.

    When I go to 127.0.0.1:8000/admin/login I can see a login page. I enter username and password. I get logged in but see empty page with 404 Not Found.

    I found another ticket which shows that this project is only for admin back-end API. The front-end needs to be installed separately.

    That's OK but in that case README.md is very confusing and it should be changed.

    1. It should remove all screenshots (which suggest that the package comes with full admin UI).
    2. It should clearly say that this project is admin back-end only and has no UI. It should point to the front-end UI repository
    3. It would also be helpful to mention, that GET /init/ page is one time use only - it stops working after creating the first admin user.
    4. Finally, the GET /admin/login page should be removed. It now renders what looks like a regular login page, which makes an impression the project has UI, but logging in leads to 404 and googling leads to a ticket where it says there is no UI and it needs to be installed separately.
    opened by PawelRoman 0
  • Error running dockerfile

    Error running dockerfile

    Good Morning! I cloned your repository and tried to run the dockerfile that comes with it to see how the application works. However, right after the container is initialized with docker compose up -d --build, the container stops and the following error is thrown in its log: image Could you please help me with this? I would love to implement an admin panel in the application I'm building, thanks in advance!

    opened by JhonataAugust0 0
Releases(v1.0.3)
A jazzy skin for the Django Admin-Interface (official repository).

Django Grappelli A jazzy skin for the Django admin interface. Grappelli is a grid-based alternative/extension to the Django administration interface.

Patrick Kranzlmueller 3.4k Dec 31, 2022
Modern theme for Django admin interface

Django Suit Modern theme for Django admin interface. Django Suit is alternative theme/skin/extension for Django administration interface. Project home

Kaspars Sprogis 2.2k Dec 29, 2022
Jazzy theme for Django

Django jazzmin (Jazzy Admin) Drop-in theme for django admin, that utilises AdminLTE 3 & Bootstrap 4 to make yo' admin look jazzy Installation pip inst

David Farrington 1.2k Jan 08, 2023
A platform used with frabit-server and frabit

A platform used with frabit-server and frabit

FrabitTech 1 Mar 03, 2022
Sandwich Batch Normalization

Sandwich Batch Normalization Code for Sandwich Batch Normalization. Introduction We present Sandwich Batch Normalization (SaBN), an extremely easy imp

VITA 48 Dec 15, 2022
A high-level app and dashboarding solution for Python

Panel provides tools for easily composing widgets, plots, tables, and other viewable objects and controls into custom analysis tools, apps, and dashboards.

HoloViz 2.5k Jan 03, 2023
Video Visual Relation Detection (VidVRD) tracklets generation. also for ACM MM Visual Relation Understanding Grand Challenge

VidVRD-tracklets This repository contains codes for Video Visual Relation Detection (VidVRD) tracklets generation based on MEGA and deepSORT. These tr

25 Dec 21, 2022
Extendable, adaptable rewrite of django.contrib.admin

django-admin2 One of the most useful parts of django.contrib.admin is the ability to configure various views that touch and alter data. django-admin2

Jazzband 1.2k Dec 29, 2022
Firebase Admin Console is a centralized platform for easy viewing and maintenance of Firestore database, the back-end API is a Python Flask app.

Firebase Admin Console is a centralized platform for easy viewing and maintenance of Firestore database, the back-end API is a Python Flask app. A starting template for developers to customize, build

Daqi Chen 1 Sep 10, 2022
Extends the Django Admin to include a extensible dashboard and navigation menu

django-admin-tools django-admin-tools is a collection of extensions/tools for the default django administration interface, it includes: a full feature

Django Admin Tools 731 Dec 28, 2022
Python code for "Machine learning: a probabilistic perspective" (2nd edition)

Python code for "Machine learning: a probabilistic perspective" (2nd edition)

Probabilistic machine learning 5.3k Dec 31, 2022
Jet Bridge (Universal) for Jet Admin – API-based Admin Panel Framework for your application

Jet Bridge for Jet Admin – Admin panel framework for your application Description About Jet Admin: https://about.jetadmin.io Live Demo: https://app.je

Jet Admin 1.3k Dec 27, 2022
Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo

Django JET Modern template for Django admin interface with improved functionality Attention! NEW JET We are proud to announce completely new Jet. Plea

Geex Arts 3.4k Dec 29, 2022
django's default admin interface made customizable. popup windows replaced by modals. :mage: :zap:

django-admin-interface django-admin-interface is a modern responsive flat admin interface customizable by the admin itself. Features Beautiful default

Fabio Caccamo 1.3k Dec 31, 2022
PyMMO is a Python-based MMO game framework using sockets and PyGame.

PyMMO is a Python framework/template of a MMO game built using PyGame on top of Python's built-in socket module.

Luis Souto Maior 61 Dec 18, 2022
FastAPI Admin Dashboard based on FastAPI and Tortoise ORM.

FastAPI ADMIN 中文文档 Introduction FastAPI-Admin is a admin dashboard based on fastapi and tortoise-orm. FastAPI-Admin provide crud feature out-of-the-bo

long2ice 1.6k Jan 02, 2023
A user-friendly JSON editing form for Django admin

A user-friendly JSON editing form for Django admin

Bharat Chauhan 141 Dec 30, 2022
"Log in as user" for the Django admin.

django-loginas About "Login as user" for the Django admin. loginas supports Python 3 only, as of version 0.4. If you're on 2, use 0.3.6. Installing dj

Stavros Korokithakis 326 Dec 03, 2022
📱 An extension for Django admin that makes interface mobile-friendly. Merged into Django 2.0

Django Flat Responsive django-flat-responsive is included as part of Django from version 2.0! 🎉 Use this app if your project is powered by an older D

elky 248 Sep 02, 2022
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs 3.x docs are avai

1.2k Jan 02, 2023