Skip to content

Quick Start

Get CRUDAdmin up and running in just a few minutes! This guide will walk you through creating your first admin interface.

Requirements

Before starting, ensure you have:

  • Python: Version 3.9 or newer
  • FastAPI: CRUDAdmin is built to work with FastAPI
  • FastCRUD: CRUDAdmin is built on top of FastCRUD for CRUD operations (which requires SQLAlchemy 2.0+ for database operations and Pydantic 2.0+ for data validation and serialization)
  • aiosqlite: Required for async SQLite operations (automatically installed as a dependency)

Installation

Install CRUDAdmin:

uv add crudadmin

Or using pip:

pip install crudadmin

For production with Redis sessions (recommended):

uv add "crudadmin[redis]"

Minimal Example

Assuming you have your SQLAlchemy model, Pydantic schemas and database connection, just skip to Using CRUDAdmin

Basic Setup

Define your SQLAlchemy model (click to expand)
from sqlalchemy import Column, Integer, String, Boolean, DateTime, func
from sqlalchemy.orm import DeclarativeBase

class Base(DeclarativeBase):
    pass

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    username = Column(String(50), unique=True, nullable=False)
    email = Column(String(100), unique=True, nullable=False)
    role = Column(String(20), default="user")
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=func.now())
Define your Pydantic schemas (click to expand)
from pydantic import BaseModel, EmailStr
from typing import Optional

class UserCreate(BaseModel):
    username: str
    email: EmailStr
    role: str = "user"
    is_active: bool = True

class UserUpdate(BaseModel):
    email: Optional[EmailStr] = None
    role: Optional[str] = None
    is_active: Optional[bool] = None
Set up your database connection (click to expand)
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

DATABASE_URL = "sqlite+aiosqlite:///./admin_demo.db"
engine = create_async_engine(DATABASE_URL, echo=True)

# Create database session dependency
async def get_session():
    async with AsyncSession(engine) as session:
        yield session

Using CRUDAdmin

Create your admin interface and mount it to your FastAPI application

main.py
from contextlib import asynccontextmanager
from fastapi import FastAPI
import os

from crudadmin import CRUDAdmin
# Import your setup (models, schemas, database)

# Create admin interface
admin = CRUDAdmin(
    session=get_session,  # Your session dependency function
    SECRET_KEY=os.environ.get("SECRET_KEY", "your-secret-key-for-development"),
    initial_admin={
        "username": "admin",
        "password": "admin123"  # Change this in production!
    }
)

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

# Initialize database and admin
@asynccontextmanager
async def lifespan(app: FastAPI):
    # Create tables
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

    # Initialize admin interface
    await admin.initialize()
    yield

# Create FastAPI app
app = FastAPI(lifespan=lifespan)

# Mount admin interface
app.mount("/admin", admin.app)

And you're all done!

Accessing Your Admin Interface

  1. Start your FastAPI server:

    uvicorn main:app --reload
    

  2. Navigate to the admin interface:

    http://localhost:8000/admin
    

  3. Log in with your admin credentials:

    • Username: admin
    • Password: admin123
  4. Start managing your data:

    • View existing users
    • Create new users
    • Edit user information
    • Delete users (if enabled)

What You Get Out of the Box

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

Next Steps

Now that you have a basic admin interface running, you might want to:

Production Considerations

Security Notice

The example above uses a simple password and secret key for demonstration. In production:

  • Use strong, randomly generated secret keys
  • Use environment variables for sensitive configuration
  • Consider using Redis for session storage: uv add "crudadmin[redis]"
  • Enable HTTPS and secure cookies
  • Set up proper logging and monitoring

For production deployment and advanced configurations, see the Advanced Topics section.