fastapi-lite-admin 0.1.3__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastapi_lite_admin-0.1.5/PKG-INFO +222 -0
- fastapi_lite_admin-0.1.5/README.md +201 -0
- fastapi_lite_admin-0.1.5/fastapi_lite_admin.egg-info/PKG-INFO +222 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/pyproject.toml +5 -1
- fastapi_lite_admin-0.1.3/PKG-INFO +0 -43
- fastapi_lite_admin-0.1.3/README.md +0 -24
- fastapi_lite_admin-0.1.3/fastapi_lite_admin.egg-info/PKG-INFO +0 -43
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/LICENSE +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/__init__.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/core/config.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/core/crud.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/core/registry.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/core/schema.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/dependencies/db.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/integrations/sqlalchemy.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/main.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/routers/admin.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/dashboard.html +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/layout.html +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/model_detail.html +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/model_form.html +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/model_list.html +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/views.py +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/SOURCES.txt +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/dependency_links.txt +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/requires.txt +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/top_level.txt +0 -0
- {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/setup.cfg +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-lite-admin
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: A lightweight, pluggable admin panel for FastAPI
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/rishiqwerty/admin-panel-fast-api
|
|
7
|
+
Project-URL: Repository, https://github.com/rishiqwerty/admin-panel-fast-api
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: fastapi>=0.100.0
|
|
12
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
13
|
+
Requires-Dist: pydantic>=2.0.0
|
|
14
|
+
Requires-Dist: jinja2>=3.1.0
|
|
15
|
+
Requires-Dist: python-multipart>=0.0.6
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: httpx; extra == "dev"
|
|
19
|
+
Requires-Dist: uvicorn; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# FastAPI Lite Admin
|
|
23
|
+
|
|
24
|
+
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
25
|
+
|
|
26
|
+
## Screenshots
|
|
27
|
+
|
|
28
|
+
### 🖥️ Dashboard / System Overview
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
### 📊 Model List View
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
### 📝 Edit/Create Record Form
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
40
|
+
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
41
|
+
- **API First**: All admin actions are available via a clean, RESTful API.
|
|
42
|
+
- **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
|
|
43
|
+
- **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
|
|
44
|
+
- **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
|
|
45
|
+
- **Custom System Logs**: Display a customizable activity feed on the main dashboard.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Install the package directly into your project:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install fastapi-lite-admin
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For development/local setup, clone the repository and run:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -e ".[dev]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Quick Start & Usage
|
|
66
|
+
|
|
67
|
+
Using `FastAPI Lite Admin` is designed to be highly explicit, simple, and require minimal boilerplate. Here is how you can set it up in your application.
|
|
68
|
+
|
|
69
|
+
### 1. Initialize the Admin Panel
|
|
70
|
+
|
|
71
|
+
Instantiate the `Admin` class and mount it to your `FastAPI` instance.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from fastapi import FastAPI
|
|
75
|
+
from fastapi_admin_lite import Admin
|
|
76
|
+
|
|
77
|
+
app = FastAPI()
|
|
78
|
+
|
|
79
|
+
admin = Admin(
|
|
80
|
+
title="Secure Control Panel", # Dashboard title
|
|
81
|
+
base_url="/admin", # URL prefix for the admin panel
|
|
82
|
+
enable_ui=True # Enable/disable Jinja-based UI
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Mount the admin router and views to your FastAPI app
|
|
86
|
+
admin.mount(app)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This will automatically create and serve:
|
|
90
|
+
- The UI dashboard at `http://localhost:8000/admin`
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Registering Models (Adding Tables)
|
|
95
|
+
|
|
96
|
+
To add database tables to your admin panel, register your models using `admin.register()`.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from database import get_db # Your SQLAlchemy session dependency
|
|
100
|
+
from models import User
|
|
101
|
+
|
|
102
|
+
admin.register(
|
|
103
|
+
model=User,
|
|
104
|
+
get_db=get_db,
|
|
105
|
+
list_display=["id", "email", "is_active", "created_at"],
|
|
106
|
+
date_field="created_at",
|
|
107
|
+
attention_filter=(User.is_active == False),
|
|
108
|
+
readonly_fields=["created_at"],
|
|
109
|
+
config={"display_name": "System Users"}
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Registration Configuration Parameters
|
|
114
|
+
|
|
115
|
+
When calling `admin.register()`, you can configure how each model is represented:
|
|
116
|
+
|
|
117
|
+
| Parameter | Type | Required | Description |
|
|
118
|
+
| :--- | :--- | :--- | :--- |
|
|
119
|
+
| **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
|
|
120
|
+
| **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
|
|
121
|
+
| **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
|
|
122
|
+
| **`date_field`** | `str` | No | Name of the datetime field (e.g. `created_at`). Required to show the "24h Activity" count cards on the dashboard and lists. |
|
|
123
|
+
| **`attention_filter`** | `SQLAlchemy Expression` | No | A SQLAlchemy binary filter expression (e.g., `User.is_active == False` or `Product.stock < 10`) used to calculate and flag rows that require moderator attention. |
|
|
124
|
+
| **`readonly_fields`** | `List[str]` | No | List of columns that cannot be modified or set via creation or updates (e.g., auto-generated columns or timestamps like `id`, `created_at`). |
|
|
125
|
+
| **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Initialization Configurations
|
|
130
|
+
|
|
131
|
+
The `Admin` class constructor supports the following parameters for customization:
|
|
132
|
+
|
|
133
|
+
| Parameter | Type | Default | Description |
|
|
134
|
+
| :--- | :--- | :--- | :--- |
|
|
135
|
+
| **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
|
|
136
|
+
| **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
|
|
137
|
+
| **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
|
|
138
|
+
| **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
|
|
139
|
+
| **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
|
|
140
|
+
| **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
|
|
141
|
+
| **`dashboard_models`** | `List[str]` | `None` | List of registered model names to display on the dashboard (if you want to restrict which registered models show on the home dashboard). |
|
|
142
|
+
| **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
|
|
143
|
+
| **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Gating Access & Security
|
|
148
|
+
|
|
149
|
+
By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
|
|
150
|
+
|
|
151
|
+
### 1. `auth_dependency`
|
|
152
|
+
|
|
153
|
+
Pass a dependency to `Admin` constructor that handles authentication.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from fastapi import Header, HTTPException
|
|
157
|
+
|
|
158
|
+
async def verify_admin_token(x_admin_token: str = Header(None)):
|
|
159
|
+
if x_admin_token != "super-secret-admin-token":
|
|
160
|
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
161
|
+
return x_admin_token
|
|
162
|
+
|
|
163
|
+
admin = Admin(
|
|
164
|
+
title="Secure Admin",
|
|
165
|
+
auth_dependency=verify_admin_token
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 2. `permission_checker`
|
|
170
|
+
|
|
171
|
+
Restrict granular user roles with a custom callable:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
|
|
175
|
+
return user.is_superuser
|
|
176
|
+
|
|
177
|
+
admin = Admin(
|
|
178
|
+
title="Staff Portal",
|
|
179
|
+
permission_checker=check_permissions
|
|
180
|
+
)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Custom Dashboard Activity Logs
|
|
186
|
+
|
|
187
|
+
Configure a live activity log feed on the dashboard homepage:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
async def fetch_system_logs():
|
|
191
|
+
# Fetch logs from a database table, file, or third-party service
|
|
192
|
+
return [
|
|
193
|
+
{"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
|
|
194
|
+
{"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
admin = Admin(
|
|
198
|
+
title="Command Center",
|
|
199
|
+
get_logs=fetch_system_logs,
|
|
200
|
+
logs_config={
|
|
201
|
+
"title": "Recent Activity Feed",
|
|
202
|
+
"columns": ["level", "timestamp", "event", "user"]
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Running the Example Application
|
|
210
|
+
|
|
211
|
+
We package a complete working example inside the `/example` directory. To run it:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# 1. Install dependencies with dev options
|
|
215
|
+
pip install -e ".[dev]"
|
|
216
|
+
|
|
217
|
+
# 2. Run the example application
|
|
218
|
+
python -m example.main
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Then visit `http://localhost:8001/admin` in your web browser. You'll be able to view logs, add/update users, search database entries, and filter elements dynamically.
|
|
222
|
+
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# FastAPI Lite Admin
|
|
2
|
+
|
|
3
|
+
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
4
|
+
|
|
5
|
+
## Screenshots
|
|
6
|
+
|
|
7
|
+
### 🖥️ Dashboard / System Overview
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
### 📊 Model List View
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
### 📝 Edit/Create Record Form
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
19
|
+
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
20
|
+
- **API First**: All admin actions are available via a clean, RESTful API.
|
|
21
|
+
- **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
|
|
22
|
+
- **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
|
|
23
|
+
- **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
|
|
24
|
+
- **Custom System Logs**: Display a customizable activity feed on the main dashboard.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install the package directly into your project:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install fastapi-lite-admin
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For development/local setup, clone the repository and run:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Quick Start & Usage
|
|
45
|
+
|
|
46
|
+
Using `FastAPI Lite Admin` is designed to be highly explicit, simple, and require minimal boilerplate. Here is how you can set it up in your application.
|
|
47
|
+
|
|
48
|
+
### 1. Initialize the Admin Panel
|
|
49
|
+
|
|
50
|
+
Instantiate the `Admin` class and mount it to your `FastAPI` instance.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from fastapi import FastAPI
|
|
54
|
+
from fastapi_admin_lite import Admin
|
|
55
|
+
|
|
56
|
+
app = FastAPI()
|
|
57
|
+
|
|
58
|
+
admin = Admin(
|
|
59
|
+
title="Secure Control Panel", # Dashboard title
|
|
60
|
+
base_url="/admin", # URL prefix for the admin panel
|
|
61
|
+
enable_ui=True # Enable/disable Jinja-based UI
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Mount the admin router and views to your FastAPI app
|
|
65
|
+
admin.mount(app)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This will automatically create and serve:
|
|
69
|
+
- The UI dashboard at `http://localhost:8000/admin`
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Registering Models (Adding Tables)
|
|
74
|
+
|
|
75
|
+
To add database tables to your admin panel, register your models using `admin.register()`.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from database import get_db # Your SQLAlchemy session dependency
|
|
79
|
+
from models import User
|
|
80
|
+
|
|
81
|
+
admin.register(
|
|
82
|
+
model=User,
|
|
83
|
+
get_db=get_db,
|
|
84
|
+
list_display=["id", "email", "is_active", "created_at"],
|
|
85
|
+
date_field="created_at",
|
|
86
|
+
attention_filter=(User.is_active == False),
|
|
87
|
+
readonly_fields=["created_at"],
|
|
88
|
+
config={"display_name": "System Users"}
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Registration Configuration Parameters
|
|
93
|
+
|
|
94
|
+
When calling `admin.register()`, you can configure how each model is represented:
|
|
95
|
+
|
|
96
|
+
| Parameter | Type | Required | Description |
|
|
97
|
+
| :--- | :--- | :--- | :--- |
|
|
98
|
+
| **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
|
|
99
|
+
| **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
|
|
100
|
+
| **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
|
|
101
|
+
| **`date_field`** | `str` | No | Name of the datetime field (e.g. `created_at`). Required to show the "24h Activity" count cards on the dashboard and lists. |
|
|
102
|
+
| **`attention_filter`** | `SQLAlchemy Expression` | No | A SQLAlchemy binary filter expression (e.g., `User.is_active == False` or `Product.stock < 10`) used to calculate and flag rows that require moderator attention. |
|
|
103
|
+
| **`readonly_fields`** | `List[str]` | No | List of columns that cannot be modified or set via creation or updates (e.g., auto-generated columns or timestamps like `id`, `created_at`). |
|
|
104
|
+
| **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Initialization Configurations
|
|
109
|
+
|
|
110
|
+
The `Admin` class constructor supports the following parameters for customization:
|
|
111
|
+
|
|
112
|
+
| Parameter | Type | Default | Description |
|
|
113
|
+
| :--- | :--- | :--- | :--- |
|
|
114
|
+
| **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
|
|
115
|
+
| **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
|
|
116
|
+
| **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
|
|
117
|
+
| **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
|
|
118
|
+
| **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
|
|
119
|
+
| **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
|
|
120
|
+
| **`dashboard_models`** | `List[str]` | `None` | List of registered model names to display on the dashboard (if you want to restrict which registered models show on the home dashboard). |
|
|
121
|
+
| **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
|
|
122
|
+
| **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Gating Access & Security
|
|
127
|
+
|
|
128
|
+
By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
|
|
129
|
+
|
|
130
|
+
### 1. `auth_dependency`
|
|
131
|
+
|
|
132
|
+
Pass a dependency to `Admin` constructor that handles authentication.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from fastapi import Header, HTTPException
|
|
136
|
+
|
|
137
|
+
async def verify_admin_token(x_admin_token: str = Header(None)):
|
|
138
|
+
if x_admin_token != "super-secret-admin-token":
|
|
139
|
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
140
|
+
return x_admin_token
|
|
141
|
+
|
|
142
|
+
admin = Admin(
|
|
143
|
+
title="Secure Admin",
|
|
144
|
+
auth_dependency=verify_admin_token
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 2. `permission_checker`
|
|
149
|
+
|
|
150
|
+
Restrict granular user roles with a custom callable:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
|
|
154
|
+
return user.is_superuser
|
|
155
|
+
|
|
156
|
+
admin = Admin(
|
|
157
|
+
title="Staff Portal",
|
|
158
|
+
permission_checker=check_permissions
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Custom Dashboard Activity Logs
|
|
165
|
+
|
|
166
|
+
Configure a live activity log feed on the dashboard homepage:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
async def fetch_system_logs():
|
|
170
|
+
# Fetch logs from a database table, file, or third-party service
|
|
171
|
+
return [
|
|
172
|
+
{"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
|
|
173
|
+
{"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
admin = Admin(
|
|
177
|
+
title="Command Center",
|
|
178
|
+
get_logs=fetch_system_logs,
|
|
179
|
+
logs_config={
|
|
180
|
+
"title": "Recent Activity Feed",
|
|
181
|
+
"columns": ["level", "timestamp", "event", "user"]
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Running the Example Application
|
|
189
|
+
|
|
190
|
+
We package a complete working example inside the `/example` directory. To run it:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# 1. Install dependencies with dev options
|
|
194
|
+
pip install -e ".[dev]"
|
|
195
|
+
|
|
196
|
+
# 2. Run the example application
|
|
197
|
+
python -m example.main
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Then visit `http://localhost:8001/admin` in your web browser. You'll be able to view logs, add/update users, search database entries, and filter elements dynamically.
|
|
201
|
+
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-lite-admin
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: A lightweight, pluggable admin panel for FastAPI
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/rishiqwerty/admin-panel-fast-api
|
|
7
|
+
Project-URL: Repository, https://github.com/rishiqwerty/admin-panel-fast-api
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: fastapi>=0.100.0
|
|
12
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
13
|
+
Requires-Dist: pydantic>=2.0.0
|
|
14
|
+
Requires-Dist: jinja2>=3.1.0
|
|
15
|
+
Requires-Dist: python-multipart>=0.0.6
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: httpx; extra == "dev"
|
|
19
|
+
Requires-Dist: uvicorn; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# FastAPI Lite Admin
|
|
23
|
+
|
|
24
|
+
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
25
|
+
|
|
26
|
+
## Screenshots
|
|
27
|
+
|
|
28
|
+
### 🖥️ Dashboard / System Overview
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
### 📊 Model List View
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
### 📝 Edit/Create Record Form
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
40
|
+
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
41
|
+
- **API First**: All admin actions are available via a clean, RESTful API.
|
|
42
|
+
- **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
|
|
43
|
+
- **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
|
|
44
|
+
- **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
|
|
45
|
+
- **Custom System Logs**: Display a customizable activity feed on the main dashboard.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Install the package directly into your project:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install fastapi-lite-admin
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For development/local setup, clone the repository and run:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -e ".[dev]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Quick Start & Usage
|
|
66
|
+
|
|
67
|
+
Using `FastAPI Lite Admin` is designed to be highly explicit, simple, and require minimal boilerplate. Here is how you can set it up in your application.
|
|
68
|
+
|
|
69
|
+
### 1. Initialize the Admin Panel
|
|
70
|
+
|
|
71
|
+
Instantiate the `Admin` class and mount it to your `FastAPI` instance.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from fastapi import FastAPI
|
|
75
|
+
from fastapi_admin_lite import Admin
|
|
76
|
+
|
|
77
|
+
app = FastAPI()
|
|
78
|
+
|
|
79
|
+
admin = Admin(
|
|
80
|
+
title="Secure Control Panel", # Dashboard title
|
|
81
|
+
base_url="/admin", # URL prefix for the admin panel
|
|
82
|
+
enable_ui=True # Enable/disable Jinja-based UI
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Mount the admin router and views to your FastAPI app
|
|
86
|
+
admin.mount(app)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This will automatically create and serve:
|
|
90
|
+
- The UI dashboard at `http://localhost:8000/admin`
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Registering Models (Adding Tables)
|
|
95
|
+
|
|
96
|
+
To add database tables to your admin panel, register your models using `admin.register()`.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from database import get_db # Your SQLAlchemy session dependency
|
|
100
|
+
from models import User
|
|
101
|
+
|
|
102
|
+
admin.register(
|
|
103
|
+
model=User,
|
|
104
|
+
get_db=get_db,
|
|
105
|
+
list_display=["id", "email", "is_active", "created_at"],
|
|
106
|
+
date_field="created_at",
|
|
107
|
+
attention_filter=(User.is_active == False),
|
|
108
|
+
readonly_fields=["created_at"],
|
|
109
|
+
config={"display_name": "System Users"}
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Registration Configuration Parameters
|
|
114
|
+
|
|
115
|
+
When calling `admin.register()`, you can configure how each model is represented:
|
|
116
|
+
|
|
117
|
+
| Parameter | Type | Required | Description |
|
|
118
|
+
| :--- | :--- | :--- | :--- |
|
|
119
|
+
| **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
|
|
120
|
+
| **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
|
|
121
|
+
| **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
|
|
122
|
+
| **`date_field`** | `str` | No | Name of the datetime field (e.g. `created_at`). Required to show the "24h Activity" count cards on the dashboard and lists. |
|
|
123
|
+
| **`attention_filter`** | `SQLAlchemy Expression` | No | A SQLAlchemy binary filter expression (e.g., `User.is_active == False` or `Product.stock < 10`) used to calculate and flag rows that require moderator attention. |
|
|
124
|
+
| **`readonly_fields`** | `List[str]` | No | List of columns that cannot be modified or set via creation or updates (e.g., auto-generated columns or timestamps like `id`, `created_at`). |
|
|
125
|
+
| **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Initialization Configurations
|
|
130
|
+
|
|
131
|
+
The `Admin` class constructor supports the following parameters for customization:
|
|
132
|
+
|
|
133
|
+
| Parameter | Type | Default | Description |
|
|
134
|
+
| :--- | :--- | :--- | :--- |
|
|
135
|
+
| **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
|
|
136
|
+
| **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
|
|
137
|
+
| **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
|
|
138
|
+
| **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
|
|
139
|
+
| **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
|
|
140
|
+
| **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
|
|
141
|
+
| **`dashboard_models`** | `List[str]` | `None` | List of registered model names to display on the dashboard (if you want to restrict which registered models show on the home dashboard). |
|
|
142
|
+
| **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
|
|
143
|
+
| **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Gating Access & Security
|
|
148
|
+
|
|
149
|
+
By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
|
|
150
|
+
|
|
151
|
+
### 1. `auth_dependency`
|
|
152
|
+
|
|
153
|
+
Pass a dependency to `Admin` constructor that handles authentication.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from fastapi import Header, HTTPException
|
|
157
|
+
|
|
158
|
+
async def verify_admin_token(x_admin_token: str = Header(None)):
|
|
159
|
+
if x_admin_token != "super-secret-admin-token":
|
|
160
|
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
161
|
+
return x_admin_token
|
|
162
|
+
|
|
163
|
+
admin = Admin(
|
|
164
|
+
title="Secure Admin",
|
|
165
|
+
auth_dependency=verify_admin_token
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 2. `permission_checker`
|
|
170
|
+
|
|
171
|
+
Restrict granular user roles with a custom callable:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
|
|
175
|
+
return user.is_superuser
|
|
176
|
+
|
|
177
|
+
admin = Admin(
|
|
178
|
+
title="Staff Portal",
|
|
179
|
+
permission_checker=check_permissions
|
|
180
|
+
)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Custom Dashboard Activity Logs
|
|
186
|
+
|
|
187
|
+
Configure a live activity log feed on the dashboard homepage:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
async def fetch_system_logs():
|
|
191
|
+
# Fetch logs from a database table, file, or third-party service
|
|
192
|
+
return [
|
|
193
|
+
{"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
|
|
194
|
+
{"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
admin = Admin(
|
|
198
|
+
title="Command Center",
|
|
199
|
+
get_logs=fetch_system_logs,
|
|
200
|
+
logs_config={
|
|
201
|
+
"title": "Recent Activity Feed",
|
|
202
|
+
"columns": ["level", "timestamp", "event", "user"]
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Running the Example Application
|
|
210
|
+
|
|
211
|
+
We package a complete working example inside the `/example` directory. To run it:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# 1. Install dependencies with dev options
|
|
215
|
+
pip install -e ".[dev]"
|
|
216
|
+
|
|
217
|
+
# 2. Run the example application
|
|
218
|
+
python -m example.main
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Then visit `http://localhost:8001/admin` in your web browser. You'll be able to view logs, add/update users, search database entries, and filter elements dynamically.
|
|
222
|
+
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "fastapi-lite-admin"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.5"
|
|
8
8
|
description = "A lightweight, pluggable admin panel for FastAPI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -30,3 +30,7 @@ exclude = ["example*"]
|
|
|
30
30
|
|
|
31
31
|
[tool.setuptools.package-data]
|
|
32
32
|
"fastapi_admin_lite.ui.templates" = ["*.html"]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://github.com/rishiqwerty/admin-panel-fast-api"
|
|
36
|
+
Repository = "https://github.com/rishiqwerty/admin-panel-fast-api"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: fastapi-lite-admin
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: A lightweight, pluggable admin panel for FastAPI
|
|
5
|
-
License: MIT
|
|
6
|
-
Requires-Python: >=3.9
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: fastapi>=0.100.0
|
|
10
|
-
Requires-Dist: sqlalchemy>=2.0.0
|
|
11
|
-
Requires-Dist: pydantic>=2.0.0
|
|
12
|
-
Requires-Dist: jinja2>=3.1.0
|
|
13
|
-
Requires-Dist: python-multipart>=0.0.6
|
|
14
|
-
Provides-Extra: dev
|
|
15
|
-
Requires-Dist: pytest; extra == "dev"
|
|
16
|
-
Requires-Dist: httpx; extra == "dev"
|
|
17
|
-
Requires-Dist: uvicorn; extra == "dev"
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
|
|
20
|
-
# FastAPI Lite Admin
|
|
21
|
-
|
|
22
|
-
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
23
|
-
|
|
24
|
-
## Features
|
|
25
|
-
|
|
26
|
-
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
27
|
-
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
28
|
-
- **API First**: All admin actions are available via a REST API.
|
|
29
|
-
- **Lightweight UI**: Simple Jinja2 templates for the dashboard and forms.
|
|
30
|
-
|
|
31
|
-
## Quick Start
|
|
32
|
-
|
|
33
|
-
(Documentation coming soon)
|
|
34
|
-
|
|
35
|
-
## Development
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Install dependencies
|
|
39
|
-
pip install -e ".[dev]"
|
|
40
|
-
|
|
41
|
-
# Run example
|
|
42
|
-
python -m example.main
|
|
43
|
-
```
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# FastAPI Lite Admin
|
|
2
|
-
|
|
3
|
-
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
8
|
-
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
9
|
-
- **API First**: All admin actions are available via a REST API.
|
|
10
|
-
- **Lightweight UI**: Simple Jinja2 templates for the dashboard and forms.
|
|
11
|
-
|
|
12
|
-
## Quick Start
|
|
13
|
-
|
|
14
|
-
(Documentation coming soon)
|
|
15
|
-
|
|
16
|
-
## Development
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
# Install dependencies
|
|
20
|
-
pip install -e ".[dev]"
|
|
21
|
-
|
|
22
|
-
# Run example
|
|
23
|
-
python -m example.main
|
|
24
|
-
```
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: fastapi-lite-admin
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: A lightweight, pluggable admin panel for FastAPI
|
|
5
|
-
License: MIT
|
|
6
|
-
Requires-Python: >=3.9
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: fastapi>=0.100.0
|
|
10
|
-
Requires-Dist: sqlalchemy>=2.0.0
|
|
11
|
-
Requires-Dist: pydantic>=2.0.0
|
|
12
|
-
Requires-Dist: jinja2>=3.1.0
|
|
13
|
-
Requires-Dist: python-multipart>=0.0.6
|
|
14
|
-
Provides-Extra: dev
|
|
15
|
-
Requires-Dist: pytest; extra == "dev"
|
|
16
|
-
Requires-Dist: httpx; extra == "dev"
|
|
17
|
-
Requires-Dist: uvicorn; extra == "dev"
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
|
|
20
|
-
# FastAPI Lite Admin
|
|
21
|
-
|
|
22
|
-
A premium, lightweight, pluggable admin panel for FastAPI and SQLAlchemy.
|
|
23
|
-
|
|
24
|
-
## Features
|
|
25
|
-
|
|
26
|
-
- **Zero-config CRUD**: Automatically generate admin interfaces for your models.
|
|
27
|
-
- **ORM Agnostic**: Initial support for SQLAlchemy, designed to support others.
|
|
28
|
-
- **API First**: All admin actions are available via a REST API.
|
|
29
|
-
- **Lightweight UI**: Simple Jinja2 templates for the dashboard and forms.
|
|
30
|
-
|
|
31
|
-
## Quick Start
|
|
32
|
-
|
|
33
|
-
(Documentation coming soon)
|
|
34
|
-
|
|
35
|
-
## Development
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# Install dependencies
|
|
39
|
-
pip install -e ".[dev]"
|
|
40
|
-
|
|
41
|
-
# Run example
|
|
42
|
-
python -m example.main
|
|
43
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/integrations/sqlalchemy.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/dashboard.html
RENAMED
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_admin_lite/ui/templates/layout.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/requires.txt
RENAMED
|
File without changes
|
{fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.5}/fastapi_lite_admin.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|