11
11
</p >
12
12
13
13
<p align =" center " >
14
- <a href =" https://pypi.org/project /crudadmin " >
15
- <img src =" https://img.shields.io/pypi/v/ crudadmin?color=%2334D058&label=pypi%20package " alt =" Package version " />
14
+ <a href =" https://github.com/igorbenav /crudadmin/actions/workflows/tests.yml " >
15
+ <img src =" https://github.com/igorbenav/ crudadmin/actions/workflows/tests.yml/badge.svg " alt =" Tests " />
16
16
</a >
17
- <a href =" https://pypi.org/project/crudadmin " >
18
- <img src =" https://img.shields.io/pypi/pyversions/crudadmin.svg?color=%2334D058 " alt =" Supported Python versions " />
17
+ <a href =" https://pypi.org/project/crudadmin/ " >
18
+ <img src =" https://img.shields.io/pypi/v/crudadmin?color=%2334D058&label=pypi%20package " alt =" PyPi Version " />
19
+ </a >
20
+ <a href =" https://pypi.org/project/crudadmin/ " >
21
+ <img src =" https://img.shields.io/pypi/pyversions/crudadmin.svg?color=%2334D058 " alt =" Supported Python Versions " />
19
22
</a >
20
23
</p >
21
24
22
- <hr >
23
- <p align =" justify " >
24
- <b >CRUDAdmin</b > is a robust admin interface generator for <b >FastAPI</b > applications, offering secure authentication, comprehensive event tracking, and essential monitoring features. Built on top of FastCRUD and SQLAlchemy, it helps you create production-ready admin panels with minimal configuration.
25
- </p >
25
+ ---
26
26
27
- < p >< b >Documentation</ b >: < a href = " https://igorbenav.github.io/crudadmin/ " > https://igorbenav. github.io/crudadmin/</ a ></ p >
27
+ ** CRUDAdmin ** is a robust admin interface generator for ** FastAPI ** applications, offering secure authentication, comprehensive event tracking, and essential monitoring features. Built with [ FastCRUD ] ( https://github.com/benavlabs/fastcrud ) and HTMX, it helps you create production-ready admin panels with minimal configuration.
28
28
29
- > [ !WARNING]
30
- > CRUDAdmin is still experimental.
29
+ ** Documentation** : [ https://igorbenav.github.io/crudadmin/ ] ( https://igorbenav.github.io/crudadmin/ )
31
30
32
- <hr >
31
+ > [ !WARNING]
32
+ > 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.
33
33
34
34
## Features
35
35
36
- - 🔒 ** Session-based Authentication** : Secure session management with inactivity timeouts and concurrent session limits
37
- - 🛡️ ** Built-in Security** : IP restrictions, HTTPS enforcement, and secure cookie handling
38
- - 📝 ** Event Tracking** : Comprehensive audit logs for all admin actions with user attribution
39
- - 🏥 ** Health Monitoring** : Real-time system status dashboard with key metrics
40
- - 📊 ** Auto-generated Interface** : Creates admin UI directly from your SQLAlchemy models
41
- - 🔍 ** Smart Filtering** : Type-aware field filtering and efficient search
42
- - 🌗 ** Modern UI** : Clean interface with dark/light theme support
43
-
44
- ## Requirements
45
-
46
- Before installing CRUDAdmin, ensure you have:
36
+ - ** 🔒 Multi-Backend Session Management** : Memory, Redis, Memcached, Database, and Hybrid backends
37
+ - ** 🛡️ Built-in Security** : CSRF protection, rate limiting, IP restrictions, HTTPS enforcement, and secure cookies
38
+ - ** 📝 Event Tracking & Audit Logs** : Comprehensive audit trails for all admin actions with user attribution
39
+ - ** 📊 Auto-generated Interface** : Creates admin UI directly from your SQLAlchemy models with intelligent field detection
40
+ - ** 🔍 Advanced Filtering** : Type-aware field filtering, search, and pagination with bulk operations
41
+ - ** 🌗 Modern UI** : Clean, responsive interface built with HTMX and [ FastCRUD] ( https://github.com/benavlabs/fastcrud )
47
42
48
- - ** FastAPI** : Latest version for the web framework
49
- - ** SQLAlchemy** : Version 2.0+ for database operations
50
- - ** Pydantic** : Version 2.0+ for data validation
43
+ ## Quick Start
51
44
52
- ## Installing
45
+ ### Installation
53
46
54
47
``` sh
55
- pip install crudadmin
48
+ uv add crudadmin
56
49
```
57
50
58
- Or using poetry:
59
-
51
+ For production with Redis sessions:
60
52
``` sh
61
- poetry add crudadmin
62
- ```
63
-
64
- ## Usage
65
-
66
- CRUDAdmin offers a straightforward way to create admin interfaces. Here's how to get started:
67
-
68
- ### Define Your Models and Schemas
69
-
70
- ** models.py**
71
- ``` python
72
- from sqlalchemy.orm import DeclarativeBase
73
- from sqlalchemy import Column, Integer, String
74
-
75
- class Base (DeclarativeBase ):
76
- pass
77
-
78
- class User (Base ):
79
- __tablename__ = " users"
80
- id = Column(Integer, primary_key = True )
81
- username = Column(String, unique = True )
82
- email = Column(String)
83
- role = Column(String)
53
+ uv add " crudadmin[redis]"
84
54
```
85
55
86
- ** schemas.py**
87
- ``` python
88
- from pydantic import BaseModel, EmailStr
89
-
90
- class UserCreate (BaseModel ):
91
- username: str
92
- email: EmailStr
93
- role: str = " user"
94
-
95
- class UserUpdate (BaseModel ):
96
- email: EmailStr | None = None
97
- role: str | None = None
56
+ Or using pip and memcached:
57
+ ``` sh
58
+ pip install " crudadmin[memcached]"
98
59
```
99
60
100
- ### Set Up the Admin Interface
61
+ ### Basic Setup
101
62
102
- ** main.py**
103
63
``` python
104
64
from contextlib import asynccontextmanager
105
65
from fastapi import FastAPI
106
66
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
107
67
from crudadmin import CRUDAdmin
108
- import os
68
+
69
+ from .user import (
70
+ User,
71
+ UserCreate,
72
+ UserUpdate,
73
+ )
109
74
110
75
# Database setup
111
76
engine = create_async_engine(" sqlite+aiosqlite:///app.db" )
@@ -114,7 +79,7 @@ session = AsyncSession(engine)
114
79
# Create admin interface
115
80
admin = CRUDAdmin(
116
81
session = session,
117
- SECRET_KEY = os.environ.get( " ADMIN_SECRET_KEY " ) ,
82
+ SECRET_KEY = " your-secret-key-here " ,
118
83
initial_admin = {
119
84
" username" : " admin" ,
120
85
" password" : " secure_password123"
@@ -145,67 +110,74 @@ app = FastAPI(lifespan=lifespan)
145
110
app.mount(" /admin" , admin.app)
146
111
```
147
112
148
- ### Enable Event Tracking
113
+ Navigate to ` /admin ` to access your admin interface with:
149
114
150
- ``` python
151
- admin = CRUDAdmin(
152
- session = session,
153
- SECRET_KEY = SECRET_KEY ,
154
- track_events = True ,
155
- admin_db_url = " postgresql+asyncpg://user:pass@localhost/admin_logs"
156
- )
115
+ - User authentication
116
+ - CRUD operations for your models
117
+ - Responsive UI with dark/light themes
118
+ - Built-in security features
157
119
158
- @asynccontextmanager
159
- async def lifespan (app : FastAPI):
160
- async with engine.begin() as conn:
161
- await conn.run_sync(Base.metadata.create_all)
162
- await admin.initialize() # Creates event tracking tables
163
- yield
120
+ ## Session Backends
121
+
122
+ ### Development (Default)
123
+ ``` python
124
+ admin = CRUDAdmin(session = session, SECRET_KEY = " key" ) # Memory backend
164
125
```
165
126
166
- ### Configure Security Features
127
+ ### Production with Redis
128
+ ``` python
129
+ admin = CRUDAdmin(session = session, SECRET_KEY = " key" ).use_redis_sessions(
130
+ redis_url = " redis://localhost:6379"
131
+ )
132
+ ```
167
133
134
+ ### Production with Security Features
168
135
``` python
169
136
admin = CRUDAdmin(
170
137
session = session,
171
138
SECRET_KEY = SECRET_KEY ,
172
- # Security settings
139
+ # Security features
173
140
allowed_ips = [" 10.0.0.1" ],
174
141
allowed_networks = [" 192.168.1.0/24" ],
175
142
secure_cookies = True ,
176
143
enforce_https = True ,
177
- # Session settings
178
- max_sessions_per_user = 5 ,
179
- session_timeout_minutes = 30
180
- )
181
-
182
- @asynccontextmanager
183
- async def lifespan (app : FastAPI):
184
- async with engine.begin() as conn:
185
- await conn.run_sync(Base.metadata.create_all)
186
- await admin.initialize() # Initializes security features
187
- yield
144
+ # Session management
145
+ max_sessions_per_user = 3 ,
146
+ session_timeout_minutes = 15 ,
147
+ # Event tracking
148
+ track_events = True
149
+ ).use_redis_sessions(redis_url = " redis://localhost:6379" )
188
150
```
189
151
190
- ## Current Limitations (coming soon)
152
+ ## Backend Options
191
153
192
- - No file upload support yet
193
- - No custom admin views (model-based only)
194
- - No custom field widgets
195
- - No SQLAlchemy relationship support
196
- - No export functionality
154
+ | Backend | Use Case | Performance | Persistence | Scalability |
155
+ | ---------| ----------| -------------| -------------| -------------|
156
+ | ** Memory** | Development/Testing | Fastest | No | Single Instance |
157
+ | ** Redis** | Production (Recommended) | Very Fast | Optional | High |
158
+ | ** Memcached** | High-Traffic Production | Very Fast | No | High |
159
+ | ** Database** | Simple Deployments | Good | Yes | Medium |
160
+ | ** Hybrid** | Enterprise/Audit Requirements | Fast | Yes | High |
197
161
198
- ## Similar Projects
162
+ ## What You Get
199
163
200
- - ** [ Django Admin] ( https://docs.djangoproject.com/en/stable/ref/contrib/admin/ ) ** : The inspiration for this project
201
- - ** [ Flask-Admin] ( https://flask-admin.readthedocs.io/ ) ** : Similar project for Flask
202
- - ** [ Sqladmin] ( https://github.com/aminalaee/sqladmin ) ** : Another FastAPI admin interface
164
+ - ** Secure Authentication** - Login/logout with session management
165
+ - ** Auto-Generated Forms** - Create and edit forms built from your Pydantic schemas
166
+ - ** Data Tables** - Paginated, sortable tables for viewing your data
167
+ - ** CRUD Operations** - Full Create, Read, Update, Delete functionality
168
+ - ** Responsive UI** - Works on desktop and mobile devices
169
+ - ** Dark/Light Themes** - Toggle between themes
170
+ - ** Input Validation** - Built-in validation using your Pydantic schemas
171
+ - ** Event Tracking** - Monitor all admin actions with audit trails
172
+ - ** Health Monitoring** - Real-time system status and diagnostics
203
173
204
- ## License
174
+ ## Documentation
205
175
206
- This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
176
+ - ** [ Quick Start] ( https://igorbenav.github.io/crudadmin/quick-start/ ) ** : Get up and running in 5 minutes
177
+ - ** [ Usage Guide] ( https://igorbenav.github.io/crudadmin/usage/overview/ ) ** : Complete usage documentation
178
+ - ** [ API Reference] ( https://igorbenav.github.io/crudadmin/api/overview/ ) ** : Full API documentation
179
+ - ** [ Advanced Topics] ( https://igorbenav.github.io/crudadmin/advanced/overview/ ) ** : Production features and configurations
207
180
208
- ## Contact
181
+ ## License
209
182
210
- Igor Benav –
[ @igorbenav ] ( https://x.com/igorbenav ) –
[email protected]
211
- [ github.com/igorbenav] ( https://github.com/igorbenav/ )
183
+ This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
0 commit comments