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)
asgi-server-timing-middleware

ASGI Server-Timing middleware An ASGI middleware that wraps the excellent yappi profiler to let you measure the execution time of any function or coro

33 Dec 15, 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 Dec 31, 2022
Example projects built using Piccolo.

Piccolo examples Here are some example Piccolo projects. Tutorials headless blog fastapi Build a documented API with an admin in minutes! Live project

15 Nov 23, 2022
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
A simple docker-compose app for orchestrating a fastapi application, a celery queue with rabbitmq(broker) and redis(backend)

fastapi - celery - rabbitmq - redis - Docker A simple docker-compose app for orchestrating a fastapi application, a celery queue with rabbitmq(broker

Kartheekasasanka Kaipa 83 Dec 19, 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
FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

RES 239 Dec 28, 2022
python template private service

Template for private python service This is a cookiecutter template for an internal REST API service, written in Python, inspired by layout-golang. Th

UrvanovCompany 15 Oct 02, 2022
API & Webapp to answer questions about COVID-19. Using NLP (Question Answering) and trusted data sources.

This open source project serves two purposes. Collection and evaluation of a Question Answering dataset to improve existing QA/search methods - COVID-

deepset 329 Nov 10, 2022
Generate FastAPI projects for high performance applications

Generate FastAPI projects for high performance applications. Based on MVC architectural pattern, WSGI + ASGI. Includes tests, pipeline, base utilities, Helm chart, and script for bootstrapping local

Radosław Szamszur 274 Jan 08, 2023
Code for my JWT auth for FastAPI tutorial

FastAPI tutorial Code for my video tutorial FastAPI tutorial What is FastAPI? FastAPI is a high-performant REST API framework for Python. It's built o

José Haro Peralta 8 Dec 16, 2022
FastAPI构建的API服务

使用FastAPI 构建的商城项目API 学习FastAPI 构建项目目录 构建项目接口: 对应博客:https://www.charmcode.cn/article/2020-06-08_vue_mall_api 声明 此项目已经不再维护, 可以参考我另外一个项目https://github.co

王小右 64 Oct 04, 2022
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
An extension for GINO to support Starlette server.

gino-starlette Introduction An extension for GINO to support starlette server. Usage The common usage looks like this: from starlette.applications imp

GINO Community 75 Dec 08, 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
Htmdf - html to pdf with support for variables using fastApi.

htmdf Converts html to pdf with support for variables using fastApi. Installation Clone this repository. git clone https://github.com/ShreehariVaasish

Shreehari 1 Jan 30, 2022
I'm curious if pydantic + fast api can be sensibly used with DDD + hex arch methodology

pydantic-ddd-exploration I'm curious if pydantic + fast api can be sensibly used with DDD + hex arch methodology Prerequisites nix direnv (nix-env -i

Olgierd Kasprowicz 2 Nov 17, 2021
A Prometheus Python client library for asyncio-based applications

aioprometheus aioprometheus is a Prometheus Python client library for asyncio-based applications. It provides metrics collection and serving capabilit

132 Dec 28, 2022
volunteer-database

This is the official CSM (Crowd source medical) database The What Now? We created this in light of the COVID-19 pandemic to allow volunteers to work t

32 Jun 21, 2022
TODO aplication made with Python's FastAPI framework and Hexagonal Architecture

FastAPI Todolist Description Todolist aplication made with Python's FastAPI framework and Hexagonal Architecture. This is a test repository for the pu

Giovanni Armane 91 Dec 31, 2022