Admin panel for FastAPI applications with SQLAlchemy models
Project description
Overwatch - Agnostic Admin Panel for FastAPI
Overwatch is a reusable, agnostic admin panel package for FastAPI applications that automatically generates CRUD interfaces for SQLAlchemy models. It provides an Admin experience with enhanced features including audit logging, permissions, and a modern TypeScript frontend built with Medusa UI.
โจ Features
- ๐ง Model Agnostic: Works with any SQLAlchemy model
- ๐จ Modern UI: TypeScript frontend with Medusa UI components
- ๐ Authentication: Secure JWT-based authentication system
- ๐ฅ Role Management: Hierarchical roles with fine-grained permissions
- ๐ Audit Logging: Complete audit trail of all admin actions
- ๐ Search & Filter: Advanced search and filtering capabilities
- ๐ Pagination: Efficient pagination for large datasets
- โก Bulk Operations: Bulk create, update, and delete operations
- ๐ค Export: Export data in various formats
- ๐๏ธ Customization: Highly configurable and extensible
- ๐ Performance: Async operations and optimized queries
๐ Quick Start
Installation
pip install overwatch-admin
Basic Usage
from fastapi import FastAPI
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from overwatch import OverwatchAdmin, OverwatchConfig
# Create FastAPI app
app = FastAPI()
# Define your models
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
username = Column(String(50), unique=True)
email = Column(String(100))
# Initialize Overwatch admin
admin = OverwatchAdmin(
app=app,
db_session=get_db_session, # Your database session dependency
models=[User], # Your SQLAlchemy models
admin_title="My Admin Panel"
)
# Configure model display
admin.configure_model(
User,
list_fields=["id", "username", "email"],
search_fields=["username", "email"],
)
app.run()
๐ Requirements
- Python 3.11+
- FastAPI 0.104+
- SQLAlchemy 2.0+
- Async database driver (asyncpg, aiosqlite, etc.)
๐๏ธ Architecture
Overwatch is built with a modular architecture:
overwatch/
โโโ core/ # Configuration and database setup
โโโ models/ # Overwatch internal models (admin, audit)
โโโ services/ # Business logic layer
โโโ api/ # FastAPI route handlers
โโโ schemas/ # Pydantic models
โโโ utils/ # Utility functions
โโโ frontend/ # TypeScript frontend (optional)
โ๏ธ Configuration
Overwatch can be configured through environment variables or direct configuration:
from overwatch import OverwatchConfig
from overwatch.core.config import SecurityConfig
config = OverwatchConfig(
admin_title="My Admin Panel",
security=SecurityConfig(
secret_key="your-secret-key",
access_token_expire_minutes=30,
password_min_length=8,
),
per_page=25,
enable_audit_log=True,
enable_dashboard=True,
cors_origins=["http://localhost:3000"],
)
Environment Variables
OVERWATCH_ADMIN_TITLE="My Admin Panel"
OVERWATCH_SECURITY__SECRET_KEY="your-secret-key"
OVERWATCH_SECURITY__ACCESS_TOKEN_EXPIRE_MINUTES=30
OVERWATCH_THEME__PRIMARY_COLOR="#3b82f6"
OVERWATCH_PER_PAGE=25
OVERWATCH_ENABLE_AUDIT_LOG=true
๐ Authentication & Authorization
Built-in Authentication
Overwatch comes with a complete authentication system separate from your application's user system:
# Create admin user
admin = await admin.create_admin(
username="superadmin",
password="secure-password",
email="admin@example.com",
role="super_admin"
)
Roles & Permissions
- Super Admin: Full access to all resources
- Admin: Standard CRUD operations
- Read Only: View-only access
Custom Permissions
admin.configure_model(
User,
permissions={
"read": "admin",
"write": "super_admin",
"delete": "super_admin"
}
)
๐ Model Configuration
Basic Configuration
admin.configure_model(
User,
list_fields=["id", "username", "email", "is_active"],
search_fields=["username", "email", "full_name"],
exclude_fields=["password_hash"],
readonly_fields=["id", "created_at"],
per_page=50,
order_by="username"
)
Custom Actions
admin.configure_model(
User,
custom_actions=[
{
"name": "activate_users",
"label": "Activate Selected",
"action": "POST",
"url": "/api/users/bulk-activate",
"icon": "user-check"
}
]
)
๐ Search & Filtering
Overwatch automatically generates search functionality based on your model fields:
admin.configure_model(
Product,
search_fields=["name", "description", "category"],
# Search will work across these text fields
)
Advanced Filtering
# Filter by status
GET /admin/api/products?is_active=true
# Search by name
GET /admin/api/products?search=laptop
# Sort by price
GET /admin/api/products?sort_by=price&sort_direction=desc
๐ Pagination
All list endpoints support pagination:
# Page 2, 25 items per page
GET /admin/api/users?page=2&per_page=25
# Response format
{
"items": [...],
"total": 150,
"page": 2,
"per_page": 25,
"pages": 6
}
โก Bulk Operations
Bulk Create
# POST /admin/api/users/bulk
{
"items": [
{"username": "user1", "email": "user1@example.com"},
{"username": "user2", "email": "user2@example.com"}
]
}
Bulk Update
# PUT /admin/api/users/bulk
{
"item_ids": [1, 2, 3],
"updates": {"is_active": false}
}
Bulk Delete
# DELETE /admin/api/users/bulk
{
"item_ids": [1, 2, 3]
}
๐ค Export
Export functionality is built-in:
# Export to CSV
GET /admin/api/users/export?format=csv
# Export to JSON
GET /admin/api/users/export?format=json
# Export with filters
GET /admin/api/users/export?format=csv&is_active=true
๐ Audit Logging
All admin actions are automatically logged:
# View audit logs
GET /admin/api/audit-logs
# Filter by admin
GET /admin/api/audit-logs?admin_id=1
# Filter by action
GET /admin/api/audit-logs?action=create
Audit Log Entry
{
"id": 123,
"admin_id": 1,
"admin_username": "superadmin",
"action": "create",
"resource_type": "User",
"resource_id": 456,
"old_values": null,
"new_values": {"username": "newuser", "email": "user@example.com"},
"ip_address": "192.168.1.100",
"user_agent": "Mozilla/5.0...",
"success": true,
"created_at": "2024-01-15T10:30:00Z"
}
๐จ Frontend Customization
Overwatch comes with a modern TypeScript frontend built with Medusa UI:
Theme Configuration
config = OverwatchConfig(
theme={
"primary_color": "#3b82f6",
"secondary_color": "#64748b",
"mode": "light", # light, dark, auto
"font_family": "Inter, system-ui, sans-serif"
}
)
Custom CSS
# Override styles in your application
static_files = {
"/admin/custom.css": "path/to/your/custom.css"
}
๐ง Advanced Usage
Custom Database
Overwatch can use a separate database:
config = OverwatchConfig(
database={
"url": "postgresql+asyncpg://overwatch:password@localhost/overwatch_db",
"echo": False
}
)
Custom Middleware
from overwatch.middleware import audit_middleware
app.add_middleware(
audit_middleware,
exclude_paths=["/health", "/metrics"]
)
Integration with Existing Admin
Overwatch can work alongside existing admin systems:
# Use different prefix to avoid conflicts
admin = OverwatchAdmin(
app=app,
db_session=get_db_session,
models=[User],
prefix="/overwatch-admin" # Different from existing /admin
)
๐งช Testing
import pytest
from fastapi.testclient import TestClient
from overwatch import OverwatchAdmin
app = FastAPI()
admin = OverwatchAdmin(app=app, db_session=get_db_session, models=[User])
client = TestClient(app)
def test_login():
response = client.post("/admin/api/auth/login", data={
"username": "admin",
"password": "password"
})
assert response.status_code == 200
def test_users_list():
# First login to get token
login_response = client.post("/admin/api/auth/login", data={
"username": "admin",
"password": "password"
})
token = login_response.json()["access_token"]
# Then access protected endpoint
response = client.get(
"/admin/api/users",
headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
๐ Deployment
Docker
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
RUN uvicorn main:app --host 0.0.0.0 --port 8000
EXPOSE 8000
Environment Variables
# Production
OVERWATCH_SECURITY__SECRET_KEY="your-very-secure-secret-key"
OVERWATCH_SECURITY__ACCESS_TOKEN_EXPIRE_MINUTES=15
OVERWATCH_DATABASE__URL="postgresql+asyncpg://user:pass@localhost/overwatch"
OVERWATCH_CORS_ORIGINS="https://admin.yourapp.com"
๐ Examples
See the examples/ directory for complete examples:
- Basic Example: Simple setup with User/Product models
- Advanced Example: Custom configuration, permissions, and actions
- Multi-DB Example: Using separate databases
- Custom UI Example: Custom frontend components
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Development Setup
git clone https://github.com/your-org/overwatch.git
cd overwatch
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check .
ruff format .
# Run type checking
pyright
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- FastAPI - The web framework that makes Overwatch possible
- SQLAlchemy - Powerful ORM for database operations
- Medusa UI - Beautiful UI component library
- Pydantic - Data validation and settings management
๐ Support
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- ๐ง Email
Overwatch - Making admin panels in FastAPI simple and beautiful. ๐
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 overwatch_admin-0.1.0.tar.gz.
File metadata
- Download URL: overwatch_admin-0.1.0.tar.gz
- Upload date:
- Size: 281.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ad066f018b3ec0e892af482f5041ef180ec53212ec2997a587c58badc9ee4d
|
|
| MD5 |
035115bcf9b1854fbc32e38597cf690c
|
|
| BLAKE2b-256 |
d415e4c8bc83cf215ccbd5668a52026a2d39129110f024f556ead2aa11d053ff
|
Provenance
The following attestation bundles were made for overwatch_admin-0.1.0.tar.gz:
Publisher:
release.yml on u3n-ai/overwatch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
overwatch_admin-0.1.0.tar.gz -
Subject digest:
68ad066f018b3ec0e892af482f5041ef180ec53212ec2997a587c58badc9ee4d - Sigstore transparency entry: 754949074
- Sigstore integration time:
-
Permalink:
u3n-ai/overwatch@e3d9c00a821e30ec94236e98840dbf99d14f5f73 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/u3n-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3d9c00a821e30ec94236e98840dbf99d14f5f73 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file overwatch_admin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: overwatch_admin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 256.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c51882c2ecf0385e27de612e328da9d9f8de93c5caaacdaa68c41abfb9f465f
|
|
| MD5 |
afbeae619292a454db1e93361000800c
|
|
| BLAKE2b-256 |
a5f8fb932c3bdfce76591831a028b58874ce9d0c663424d2cd2175622f7a415f
|
Provenance
The following attestation bundles were made for overwatch_admin-0.1.0-py3-none-any.whl:
Publisher:
release.yml on u3n-ai/overwatch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
overwatch_admin-0.1.0-py3-none-any.whl -
Subject digest:
5c51882c2ecf0385e27de612e328da9d9f8de93c5caaacdaa68c41abfb9f465f - Sigstore transparency entry: 754949111
- Sigstore integration time:
-
Permalink:
u3n-ai/overwatch@e3d9c00a821e30ec94236e98840dbf99d14f5f73 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/u3n-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3d9c00a821e30ec94236e98840dbf99d14f5f73 -
Trigger Event:
workflow_dispatch
-
Statement type: