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/Flask/Django easiest way.
FastAdmin is designed to be minimalistic, functional and yet familiar.
Getting Started
Installation
Install the package using pip:
pip install fastadmin
Setup ENV variables
export ADMIN_USER_MODEL = User
export ADMIN_USER_MODEL_USERNAME_FIELD = username
export ADMIN_SECRET_KEY = secret_key
For additional information see Settings documentation.
Quick Tutorial
Setup FastAdmin for framework
For FastAPI:
from fastapi import FastAPI
from fastadmin.fastapi import app as admin_app
...
app = FastAPI()
...
app.mount("/admin", admin_app)
...
Run your project (see https://fastapi.tiangolo.com/tutorial/first-steps/):
uvicorn ...
Go to http://localhost:8000/admin.
For additional information see ModelAdmin and InlineModelAdmin documentation.
For Django and Flask:
Coming soon...
Register ORM models
You have to implement authenticate method for FastAdmin authentication on AdminModel class which is registered for ADMIN_USER_MODEL.
For Tortoise ORM:
import bcrypt
from tortoise.models import Model
from fastadmin import register
from fastadmin.tortoise import TortoiseModelAdmin
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):
label_fields = ("username",)
exclude = ("hash_password",)
list_display = ("id", "username", "is_superuser", "is_active")
list_display_links = ("id", "username")
list_filter = ("id", "username", "is_superuser", "is_active")
search_fields = ("username",)
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):
label_fields = ("name",)
list_display = ("id", "name")
list_display_links = ("id",)
list_filter = ("id", "name")
search_fields = ("name",)
For SQLAlchemy and PonyORM:
Coming soon...
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.18-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81bdfcc17f13258fda276face1e79d62d710c970f5b5d7cce18f120f47e04313 |
|
MD5 | 9f529b0031ce6fb9f846da8e9c46d377 |
|
BLAKE2b-256 | 7b1cba64bea677df110e733ce85a036f96c8c64c6b75e3cf5d08f94163a9d1ac |