Skip to main content

FastAPI-based admin interface with authentication, event logging and CRUD operations

Project description

CRUDAdmin

CRUDAdmin logo

Modern admin interface for FastAPI with built-in authentication, event tracking, and security features

Tests PyPi Version Supported Python Versions


CRUDAdmin is a robust admin interface generator for FastAPI applications, offering secure authentication, comprehensive event tracking, and essential monitoring features. Built with FastCRUD and HTMX, it helps you create production-ready admin panels with minimal configuration.

Documentation: https://igorbenav.github.io/crudadmin/

[!WARNING]
CRUDAdmin is still experimental. While actively developed and tested, APIs may change between versions. Upgrade with caution in production environments, always carefuly reading the changelog.

Features

  • 🔒 Multi-Backend Session Management: Memory, Redis, Memcached, Database, and Hybrid backends
  • 🛡️ Built-in Security: CSRF protection, rate limiting, IP restrictions, HTTPS enforcement, and secure cookies
  • 📝 Event Tracking & Audit Logs: Comprehensive audit trails for all admin actions with user attribution
  • 📊 Auto-generated Interface: Creates admin UI directly from your SQLAlchemy models with intelligent field detection
  • 🔍 Advanced Filtering: Type-aware field filtering, search, and pagination with bulk operations
  • 🌗 Modern UI: Clean, responsive interface built with HTMX and FastCRUD

Quick Start

Installation

uv add crudadmin

For production with Redis sessions:

uv add "crudadmin[redis]"

Or using pip and memcached:

pip install "crudadmin[memcached]"

Basic Setup

from contextlib import asynccontextmanager
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from crudadmin import CRUDAdmin

from .user import (
    User,
    UserCreate,
    UserUpdate,
)

# Database setup
engine = create_async_engine("sqlite+aiosqlite:///app.db")
session = AsyncSession(engine)

# Create admin interface
admin = CRUDAdmin(
    session=session,
    SECRET_KEY="your-secret-key-here",
    initial_admin={
        "username": "admin",
        "password": "secure_password123"
    }
)

# Add models to admin
admin.add_view(
    model=User,
    create_schema=UserCreate,
    update_schema=UserUpdate,
    allowed_actions={"view", "create", "update"}
)

# Setup FastAPI with proper initialization
@asynccontextmanager
async def lifespan(app: FastAPI):
    # Initialize database tables
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)
    
    # Initialize admin interface
    await admin.initialize()
    yield

# Create and mount the app
app = FastAPI(lifespan=lifespan)
app.mount("/admin", admin.app)

Navigate to /admin to access your admin interface with:

  • User authentication
  • CRUD operations for your models
  • Responsive UI with dark/light themes
  • Built-in security features

Session Backends

Development (Default)

admin = CRUDAdmin(session=session, SECRET_KEY="key")  # Memory backend

Production with Redis

admin = CRUDAdmin(session=session, SECRET_KEY="key").use_redis_sessions(
    redis_url="redis://localhost:6379"
)

Production with Security Features

admin = CRUDAdmin(
    session=session,
    SECRET_KEY=SECRET_KEY,
    # Security features
    allowed_ips=["10.0.0.1"],
    allowed_networks=["192.168.1.0/24"],
    secure_cookies=True,
    enforce_https=True,
    # Session management
    max_sessions_per_user=3,
    session_timeout_minutes=15,
    # Event tracking
    track_events=True
).use_redis_sessions(redis_url="redis://localhost:6379")

Backend Options

Backend Use Case Performance Persistence Scalability
Memory Development/Testing Fastest No Single Instance
Redis Production (Recommended) Very Fast Optional High
Memcached High-Traffic Production Very Fast No High
Database Simple Deployments Good Yes Medium
Hybrid Enterprise/Audit Requirements Fast Yes High

What You Get

  • Secure Authentication - Login/logout with session management
  • Auto-Generated Forms - Create and edit forms built from your Pydantic schemas
  • Data Tables - Paginated, sortable tables for viewing your data
  • CRUD Operations - Full Create, Read, Update, Delete functionality
  • Responsive UI - Works on desktop and mobile devices
  • Dark/Light Themes - Toggle between themes
  • Input Validation - Built-in validation using your Pydantic schemas
  • Event Tracking - Monitor all admin actions with audit trails
  • Health Monitoring - Real-time system status and diagnostics

Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

crudadmin-0.3.0.tar.gz (185.8 kB view details)

Uploaded Source

Built Distribution

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

crudadmin-0.3.0-py3-none-any.whl (212.6 kB view details)

Uploaded Python 3

File details

Details for the file crudadmin-0.3.0.tar.gz.

File metadata

  • Download URL: crudadmin-0.3.0.tar.gz
  • Upload date:
  • Size: 185.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for crudadmin-0.3.0.tar.gz
Algorithm Hash digest
SHA256 27bfca2ef6586b75d600991ab0b31c4fdba091ce7edfd9544056a3bb7f39a811
MD5 6ff8f25b958fa767dfcfa7bbc288c0b8
BLAKE2b-256 201dbc603ffa0e8033ddc3d8d41cab91125eb1c5ef25a33673bb6618cdf69f75

See more details on using hashes here.

File details

Details for the file crudadmin-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: crudadmin-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 212.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for crudadmin-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66c74b4735bc73859f33248768010b44066aea321e23b850715e01460038cabc
MD5 d2c68e01f606ab1970724e5c9afb9569
BLAKE2b-256 3eaf0c9a8509a6714db25a223aee76cf0b82bd2c33c749df2097e897fea1a88d

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