Admin for FastAPI and Starlette
Project description
Daisy Admin for Starlette/FastAPI
Documentation: https://docs.bhuwanpandey.com.np
Source Code: https://github.com/BhuwanPandey/fastdaisy-admin
Fastdaisy-admin is an admin panel with DaisyUI for managing SQLAlchemy models. It offers a dashboard experience similar to Django Admin and combining the design of django-daisy with the same functionality of Sqladmin.
Features
-
SQLAlchemy sync/async Core Database ORM
-
Starlette sync/async Backend Server
-
WTForms Form Building
-
SQLModel sync/async Database ORM
-
DaisyUI Admin UI
-
Django-Admin Similar Features
Installation
Install using pip:
pip install fastdaisy-admin
Install using uv:
uv add fastdaisy-admin
Quickstart
import contextlib
from sqlalchemy import Column, Integer, String, Text, create_engine, ForeignKey
from sqlalchemy.orm import declarative_base,relationship,sessionmaker
Base = declarative_base()
engine = create_engine(
"sqlite:///example.db",
connect_args={"check_same_thread": False},
)
Session = sessionmaker(bind=engine)
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String)
books = relationship("Book", back_populates="author", cascade="all, delete-orphan")
class Book(Base):
__tablename__ = 'books'
id = Column(Integer, primary_key=True)
title = Column(String)
description = Column(Text)
author_id = Column(Integer, ForeignKey('users.id'))
author = relationship("User", back_populates="books")
@contextlib.asynccontextmanager
async def lifespan(app):
Base.metadata.create_all(engine) # create teables
yield
secret_key="secret_key"
With FastAPI:
from fastapi import FastAPI
from fastdaisy_admin import Admin, ModelView
app = FastAPI(lifespan=lifespan)
admin = Admin(
app,
secret_key,
engine
)
class UserAdmin(ModelView):
model=User
column_list = [User.id, User.name]
admin.add_view(UserAdmin)
With Starlette:
from fastdaisy_admin import Admin, ModelView
from starlette.applications import Starlette
app = Starlette(lifespan=lifespan)
admin = Admin(
app,
secret_key,
engine
)
class BookAdmin(ModelView):
model=Book
column_list = ['id', Book.title]
admin.add_view(UserAdmin)
Now visiting /admin on your browser you can see the Admin dashboard.
To active authentication
from fastdaisy_admin.auth.models import BaseUser
#override BaseUser [optional]
class User(Base, BaseUser):
__tablename__ = "users"
books = relationship("Book", back_populates="author", cascade="all, delete-orphan")
class Book(Base):
__tablename__ = 'books'
...
admin = Admin(
app,
secret_key,
engine,
authentication=True,
auth_model=User
)
create superuser with
fastdaisy-admin createsuperuser
[!WARNING]
This project is still under active development.
Current test coverage is around 91%, and work is ongoing to reach 100%.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastdaisy_admin-0.0.8.tar.gz.
File metadata
- Download URL: fastdaisy_admin-0.0.8.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
014dcf35f3d084aee1934563cc6ad12f663e1993feb62f358332f7b78480a887
|
|
| MD5 |
7957f1cf71545b0f5877cc42c809b2ef
|
|
| BLAKE2b-256 |
6b2969dbc72902a707d7534310f3aba1bc8e1cadad82ede3e0aeaf0c58b4daa6
|
File details
Details for the file fastdaisy_admin-0.0.8-py3-none-any.whl.
File metadata
- Download URL: fastdaisy_admin-0.0.8-py3-none-any.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be87e84617f34e4486b9d8ac88bd2351b0289d4e0ed5eb85c94887ad7d6719f2
|
|
| MD5 |
a87ca4139ed71fed762b08a3ed0e68c4
|
|
| BLAKE2b-256 |
32c7542feff3007ee955baa6895e26e956198ee37b10251b8095fb97242a9aa2
|