No project description provided
Project description
Admin Dashboard App for FastAPI
Screenshots
Introduction
FastAdmin is an easy-to-use Admin App for FastAPI inspired by Django Admin.
FastAdmin was built with relations in mind and admiration for the excellent and popular Django Admin. It's engraved in its design that you may configure your admin dashboard for FastAPI easiest way.
Note
FastAdmin supports only Tortoise ORM (SQLAlchemy, Pony ORM and others are in plans).
Why was FastAdmin built?
FastAPI is gaining huge popularity as an asyncio, minimalistic API framework, but there is no simple and clear system for administration your data.
Hence we started FastAdmin.
FastAdmin is designed to be minimalistic, functional, yet familiar, to ease the migration of developers wishing to switch to FastAPI from Django.
Getting Started
Installation
First you have to install FastAdmin like this:
pip install fastadmin
or using poetry
poetry install fastadmin
Quick Tutorial
Mount FastAdmin app
First of all you need to mount FastAdmin app into your app. Use prefix "/admin" as default for now. You can change it later.
Example:
from fastapi import FastAPI
from fastadmin import admin_app
...
app = FastAPI()
...
app.mount("/admin", admin_app)
...
Setup ENV variables
Setup the following env variables to configure FastAdmin (add to .env or export them like on example):
Example:
export ADMIN_USER_MODEL = User
export ADMIN_USER_MODEL_USERNAME_FIELD = username
export ADMIN_SECRET_KEY = secret_key
- ADMIN_USER_MODEL - a name of your User model (has to be registered in FastAdmin later)
- ADMIN_USER_MODEL_USERNAME_FIELD - an username field (unique field from your user table) for authentication (could be email, or phone)
- ADMIN_SECRET_KEY - a secret key (generate a strong secret key and provide here)
Register ORM models
Implement an authenticate method for ModelAdmin with registered model ADMIN_USER_MODEL
Example (for Tortoise ORM):
import bcrypt
from tortoise.models import Model
from fastadmin import TortoiseModelAdmin, register
class User(Model):
username = fields.CharField(max_length=255, unique=True)
hash_password = fields.CharField(max_length=255)
is_superuser = fields.BooleanField(default=False)
is_active = fields.BooleanField(default=False)
...
class Group(Model):
name = fields.CharField(max_length=255)
...
@register(User)
class UserAdmin(TortoiseModelAdmin):
async def authenticate(self, username: str, password: str) -> UUID | int | None:
user = await User.filter(username=username, is_superuser=True).first()
if not user:
return None
if not bcrypt.checkpw(password.encode(), user.hash_password.encode()):
return None
return user.id
@register(Group)
class GroupAdmin(TortoiseModelAdmin):
pass
Run your project
Run your project (see https://fastapi.tiangolo.com/tutorial/first-steps/):
uvicorn ...
Go to http://localhost:8000/admin.
Documentation
See full documentation here.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastadmin-0.1.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0557a0594af8f7da2228df1a740ee373398332d4bcfcd79738db07d1f86c90e8 |
|
MD5 | 45a5e9c9d095e343b3dc33c0549e555a |
|
BLAKE2b-256 | ce5858a3112d699d602aa64e9a3926bdd71a451c30f76c34adaf2fa3e63c4dd8 |