Skip to main content

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

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(BookAdmin)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastdaisy_admin-0.0.81.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastdaisy_admin-0.0.81-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file fastdaisy_admin-0.0.81.tar.gz.

File metadata

  • Download URL: fastdaisy_admin-0.0.81.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for fastdaisy_admin-0.0.81.tar.gz
Algorithm Hash digest
SHA256 97ef9a346c08e4320d42079a7b0391c79ed6bbf4dc0929a05c519486b1108217
MD5 4177dda2674de0a906ce28c4e8f84cd6
BLAKE2b-256 fe1431454fa5c4e9c04ccfd9f038898ce7572e37666b7c95246c61ee33d69039

See more details on using hashes here.

File details

Details for the file fastdaisy_admin-0.0.81-py3-none-any.whl.

File metadata

File hashes

Hashes for fastdaisy_admin-0.0.81-py3-none-any.whl
Algorithm Hash digest
SHA256 efdcfeccef7b857941b4caf10cc93af943bdc704353f593a137814844522ce79
MD5 7bb315a7749aa36ad35b9e74e3992b7d
BLAKE2b-256 fdba876b95261e426c960d8671f88a83502d85d3fd8f14875b2e0f8852009913

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page