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)
row level security for FastAPI framework

Row Level Permissions for FastAPI While trying out the excellent FastApi framework there was one peace missing for me: an easy, declarative way to def

Holger Frey 315 Dec 25, 2022
Monitor Python applications using Spring Boot Admin

Pyctuator Monitor Python web apps using Spring Boot Admin. Pyctuator supports Flask, FastAPI, aiohttp and Tornado. Django support is planned as well.

SolarEdge Technologies 145 Dec 28, 2022
Backend Skeleton using FastAPI and Sqlalchemy ORM

Backend API Skeleton Based on @tiangolo's full stack postgres template, with some things added, some things removed, and some things changed. This is

David Montague 18 Oct 31, 2022
Python supercharged for the fastai library

Welcome to fastcore Python goodies to make your coding faster, easier, and more maintainable Python is a powerful, dynamic language. Rather than bake

fast.ai 810 Jan 06, 2023
A Nepali Dictionary API made using FastAPI.

Nepali Dictionary API A Nepali dictionary api created using Fast API and inspired from https://github.com/nirooj56/Nepdict. You can say this is just t

Nishant Sapkota 4 Mar 18, 2022
OpenAPI generated FastAPI server

OpenAPI generated FastAPI server This Python package is automatically generated by the OpenAPI Generator project: API version: 1.0.0 Build package: or

microbo 1 Oct 31, 2021
📦 Autowiring dependency injection container for python 3

Lagom - Dependency injection container What Lagom is a dependency injection container designed to give you "just enough" help with building your depen

Steve B 146 Dec 29, 2022
sample web application built with FastAPI + uvicorn

SPARKY Sample web application built with FastAPI & Python 3.8 shows simple Flask-like structure with a Bootstrap template index.html also has a backgr

mrx 21 Jan 03, 2022
FastAPI + Django experiment

django-fastapi-example This is an experiment to demonstrate one potential way of running FastAPI with Django. It won't be actively maintained. If you'

Jordan Eremieff 78 Jan 03, 2023
A Jupyter server based on FastAPI (Experimental)

jupyverse is experimental and should not be used in place of jupyter-server, which is the official Jupyter server.

Jupyter Server 122 Dec 27, 2022
FastAPI on Google Cloud Run

cloudrun-fastapi Boilerplate for running FastAPI on Google Cloud Run with Google Cloud Build for deployment. For all documentation visit the docs fold

Anthony Corletti 139 Dec 27, 2022
Example of using FastAPI and MongoDB database.

FastAPI Todo Application Example of using FastAPI and MangoDB database. 💡 Prerequisites Python ⚙️ Build & Run The first thing to do is to clone the r

Bobynets Ivan 1 Oct 29, 2021
Install multiple versions of r2 and its plugins via Pip on any system!

r2env This repository contains the tool available via pip to install and manage multiple versions of radare2 and its plugins. r2-tools doesn't conflic

radare org 18 Oct 11, 2022
Adds integration of the Jinja template language to FastAPI.

fastapi-jinja Adds integration of the Jinja template language to FastAPI. This is inspired and based off fastapi-chamelon by Mike Kennedy. Check that

Marc Brooks 58 Nov 29, 2022
官方文档已经有翻译的人在做了,

FastAPI 框架,高性能,易学,快速编码,随时可供生产 文档:https://fastapi.tiangolo.com 源码:https://github.com/tiangolo/fastapi FastAPI 是一个现代、快速(高性能)的 Web 框架,基于标准 Python 类型提示,使用

ApacheCN 27 Nov 11, 2022
FastAPI Learning Example,对应中文视频学习教程:https://space.bilibili.com/396891097

视频教学地址 中文学习教程 1、本教程每一个案例都可以独立跑,前提是安装好依赖包。 2、本教程并未按照官方教程顺序,而是按照实际使用顺序编排。 Video Teaching Address FastAPI Learning Example 1.Each case in this tutorial c

381 Dec 11, 2022
The template for building scalable web APIs based on FastAPI, Tortoise ORM and other.

FastAPI and Tortoise ORM. Powerful but simple template for web APIs w/ FastAPI (as web framework) and Tortoise-ORM (for working via database without h

prostomarkeloff 95 Jan 08, 2023
A rate limiter for Starlette and FastAPI

SlowApi A rate limiting library for Starlette and FastAPI adapted from flask-limiter. Note: this is alpha quality code still, the API may change, and

Laurent Savaete 565 Jan 02, 2023
signal-cli-rest-api is a wrapper around signal-cli and allows you to interact with it through http requests

signal-cli-rest-api signal-cli-rest-api is a wrapper around signal-cli and allows you to interact with it through http requests. Features register/ver

Sebastian Noel Lübke 31 Dec 09, 2022
Recommend recipes based on what ingredients you have at home

🌱 MyChef 📦 Overview MyChef is an application that helps you decide what meal to make based on what you have at home. Simply enter in ingredients you

Logan Connolly 44 Nov 08, 2022