fastapi-lite-admin 0.1.3__tar.gz → 0.1.4__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.
Files changed (28) hide show
  1. fastapi_lite_admin-0.1.4/PKG-INFO +209 -0
  2. fastapi_lite_admin-0.1.4/README.md +190 -0
  3. fastapi_lite_admin-0.1.4/fastapi_lite_admin.egg-info/PKG-INFO +209 -0
  4. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/pyproject.toml +1 -1
  5. fastapi_lite_admin-0.1.3/PKG-INFO +0 -43
  6. fastapi_lite_admin-0.1.3/README.md +0 -24
  7. fastapi_lite_admin-0.1.3/fastapi_lite_admin.egg-info/PKG-INFO +0 -43
  8. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/LICENSE +0 -0
  9. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/__init__.py +0 -0
  10. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/core/config.py +0 -0
  11. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/core/crud.py +0 -0
  12. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/core/registry.py +0 -0
  13. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/core/schema.py +0 -0
  14. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/dependencies/db.py +0 -0
  15. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/integrations/sqlalchemy.py +0 -0
  16. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/main.py +0 -0
  17. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/routers/admin.py +0 -0
  18. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/templates/dashboard.html +0 -0
  19. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/templates/layout.html +0 -0
  20. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/templates/model_detail.html +0 -0
  21. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/templates/model_form.html +0 -0
  22. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/templates/model_list.html +0 -0
  23. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_admin_lite/ui/views.py +0 -0
  24. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_lite_admin.egg-info/SOURCES.txt +0 -0
  25. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_lite_admin.egg-info/dependency_links.txt +0 -0
  26. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_lite_admin.egg-info/requires.txt +0 -0
  27. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/fastapi_lite_admin.egg-info/top_level.txt +0 -0
  28. {fastapi_lite_admin-0.1.3 → fastapi_lite_admin-0.1.4}/setup.cfg +0 -0
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastapi-lite-admin
3
+ Version: 0.1.4
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 clean, RESTful API.
29
+ - **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
30
+ - **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
31
+ - **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
32
+ - **Custom System Logs**: Display a customizable activity feed on the main dashboard.
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ Install the package directly into your project:
39
+
40
+ ```bash
41
+ pip install fastapi-lite-admin
42
+ ```
43
+
44
+ For development/local setup, clone the repository and run:
45
+
46
+ ```bash
47
+ pip install -e ".[dev]"
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Quick Start & Usage
53
+
54
+ 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.
55
+
56
+ ### 1. Initialize the Admin Panel
57
+
58
+ Instantiate the `Admin` class and mount it to your `FastAPI` instance.
59
+
60
+ ```python
61
+ from fastapi import FastAPI
62
+ from fastapi_admin_lite import Admin
63
+
64
+ app = FastAPI()
65
+
66
+ admin = Admin(
67
+ title="Secure Control Panel", # Dashboard title
68
+ base_url="/admin", # URL prefix for the admin panel
69
+ enable_ui=True # Enable/disable Jinja-based UI
70
+ )
71
+
72
+ # Mount the admin router and views to your FastAPI app
73
+ admin.mount(app)
74
+ ```
75
+
76
+ This will automatically create and serve:
77
+ - The UI dashboard at `http://localhost:8000/admin`
78
+
79
+ ---
80
+
81
+ ## Registering Models (Adding Tables)
82
+
83
+ To add database tables to your admin panel, register your models using `admin.register()`.
84
+
85
+ ```python
86
+ from database import get_db # Your SQLAlchemy session dependency
87
+ from models import User
88
+
89
+ admin.register(
90
+ model=User,
91
+ get_db=get_db,
92
+ list_display=["id", "email", "is_active", "created_at"],
93
+ date_field="created_at",
94
+ attention_filter=(User.is_active == False),
95
+ readonly_fields=["created_at"],
96
+ config={"display_name": "System Users"}
97
+ )
98
+ ```
99
+
100
+ ### Registration Configuration Parameters
101
+
102
+ When calling `admin.register()`, you can configure how each model is represented:
103
+
104
+ | Parameter | Type | Required | Description |
105
+ | :--- | :--- | :--- | :--- |
106
+ | **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
107
+ | **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
108
+ | **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
109
+ | **`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. |
110
+ | **`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. |
111
+ | **`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`). |
112
+ | **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
113
+
114
+ ---
115
+
116
+ ## Initialization Configurations
117
+
118
+ The `Admin` class constructor supports the following parameters for customization:
119
+
120
+ | Parameter | Type | Default | Description |
121
+ | :--- | :--- | :--- | :--- |
122
+ | **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
123
+ | **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
124
+ | **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
125
+ | **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
126
+ | **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
127
+ | **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
128
+ | **`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). |
129
+ | **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
130
+ | **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
131
+
132
+ ---
133
+
134
+ ## Gating Access & Security
135
+
136
+ By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
137
+
138
+ ### 1. `auth_dependency`
139
+
140
+ Pass a dependency to `Admin` constructor that handles authentication.
141
+
142
+ ```python
143
+ from fastapi import Header, HTTPException
144
+
145
+ async def verify_admin_token(x_admin_token: str = Header(None)):
146
+ if x_admin_token != "super-secret-admin-token":
147
+ raise HTTPException(status_code=401, detail="Unauthorized")
148
+ return x_admin_token
149
+
150
+ admin = Admin(
151
+ title="Secure Admin",
152
+ auth_dependency=verify_admin_token
153
+ )
154
+ ```
155
+
156
+ ### 2. `permission_checker`
157
+
158
+ Restrict granular user roles with a custom callable:
159
+
160
+ ```python
161
+ async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
162
+ return user.is_superuser
163
+
164
+ admin = Admin(
165
+ title="Staff Portal",
166
+ permission_checker=check_permissions
167
+ )
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Custom Dashboard Activity Logs
173
+
174
+ Configure a live activity log feed on the dashboard homepage:
175
+
176
+ ```python
177
+ async def fetch_system_logs():
178
+ # Fetch logs from a database table, file, or third-party service
179
+ return [
180
+ {"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
181
+ {"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
182
+ ]
183
+
184
+ admin = Admin(
185
+ title="Command Center",
186
+ get_logs=fetch_system_logs,
187
+ logs_config={
188
+ "title": "Recent Activity Feed",
189
+ "columns": ["level", "timestamp", "event", "user"]
190
+ }
191
+ )
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Running the Example Application
197
+
198
+ We package a complete working example inside the `/example` directory. To run it:
199
+
200
+ ```bash
201
+ # 1. Install dependencies with dev options
202
+ pip install -e ".[dev]"
203
+
204
+ # 2. Run the example application
205
+ python -m example.main
206
+ ```
207
+
208
+ 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.
209
+
@@ -0,0 +1,190 @@
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 clean, RESTful API.
10
+ - **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
11
+ - **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
12
+ - **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
13
+ - **Custom System Logs**: Display a customizable activity feed on the main dashboard.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ Install the package directly into your project:
20
+
21
+ ```bash
22
+ pip install fastapi-lite-admin
23
+ ```
24
+
25
+ For development/local setup, clone the repository and run:
26
+
27
+ ```bash
28
+ pip install -e ".[dev]"
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Quick Start & Usage
34
+
35
+ 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.
36
+
37
+ ### 1. Initialize the Admin Panel
38
+
39
+ Instantiate the `Admin` class and mount it to your `FastAPI` instance.
40
+
41
+ ```python
42
+ from fastapi import FastAPI
43
+ from fastapi_admin_lite import Admin
44
+
45
+ app = FastAPI()
46
+
47
+ admin = Admin(
48
+ title="Secure Control Panel", # Dashboard title
49
+ base_url="/admin", # URL prefix for the admin panel
50
+ enable_ui=True # Enable/disable Jinja-based UI
51
+ )
52
+
53
+ # Mount the admin router and views to your FastAPI app
54
+ admin.mount(app)
55
+ ```
56
+
57
+ This will automatically create and serve:
58
+ - The UI dashboard at `http://localhost:8000/admin`
59
+
60
+ ---
61
+
62
+ ## Registering Models (Adding Tables)
63
+
64
+ To add database tables to your admin panel, register your models using `admin.register()`.
65
+
66
+ ```python
67
+ from database import get_db # Your SQLAlchemy session dependency
68
+ from models import User
69
+
70
+ admin.register(
71
+ model=User,
72
+ get_db=get_db,
73
+ list_display=["id", "email", "is_active", "created_at"],
74
+ date_field="created_at",
75
+ attention_filter=(User.is_active == False),
76
+ readonly_fields=["created_at"],
77
+ config={"display_name": "System Users"}
78
+ )
79
+ ```
80
+
81
+ ### Registration Configuration Parameters
82
+
83
+ When calling `admin.register()`, you can configure how each model is represented:
84
+
85
+ | Parameter | Type | Required | Description |
86
+ | :--- | :--- | :--- | :--- |
87
+ | **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
88
+ | **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
89
+ | **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
90
+ | **`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. |
91
+ | **`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. |
92
+ | **`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`). |
93
+ | **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
94
+
95
+ ---
96
+
97
+ ## Initialization Configurations
98
+
99
+ The `Admin` class constructor supports the following parameters for customization:
100
+
101
+ | Parameter | Type | Default | Description |
102
+ | :--- | :--- | :--- | :--- |
103
+ | **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
104
+ | **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
105
+ | **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
106
+ | **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
107
+ | **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
108
+ | **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
109
+ | **`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). |
110
+ | **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
111
+ | **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
112
+
113
+ ---
114
+
115
+ ## Gating Access & Security
116
+
117
+ By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
118
+
119
+ ### 1. `auth_dependency`
120
+
121
+ Pass a dependency to `Admin` constructor that handles authentication.
122
+
123
+ ```python
124
+ from fastapi import Header, HTTPException
125
+
126
+ async def verify_admin_token(x_admin_token: str = Header(None)):
127
+ if x_admin_token != "super-secret-admin-token":
128
+ raise HTTPException(status_code=401, detail="Unauthorized")
129
+ return x_admin_token
130
+
131
+ admin = Admin(
132
+ title="Secure Admin",
133
+ auth_dependency=verify_admin_token
134
+ )
135
+ ```
136
+
137
+ ### 2. `permission_checker`
138
+
139
+ Restrict granular user roles with a custom callable:
140
+
141
+ ```python
142
+ async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
143
+ return user.is_superuser
144
+
145
+ admin = Admin(
146
+ title="Staff Portal",
147
+ permission_checker=check_permissions
148
+ )
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Custom Dashboard Activity Logs
154
+
155
+ Configure a live activity log feed on the dashboard homepage:
156
+
157
+ ```python
158
+ async def fetch_system_logs():
159
+ # Fetch logs from a database table, file, or third-party service
160
+ return [
161
+ {"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
162
+ {"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
163
+ ]
164
+
165
+ admin = Admin(
166
+ title="Command Center",
167
+ get_logs=fetch_system_logs,
168
+ logs_config={
169
+ "title": "Recent Activity Feed",
170
+ "columns": ["level", "timestamp", "event", "user"]
171
+ }
172
+ )
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Running the Example Application
178
+
179
+ We package a complete working example inside the `/example` directory. To run it:
180
+
181
+ ```bash
182
+ # 1. Install dependencies with dev options
183
+ pip install -e ".[dev]"
184
+
185
+ # 2. Run the example application
186
+ python -m example.main
187
+ ```
188
+
189
+ 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.
190
+
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastapi-lite-admin
3
+ Version: 0.1.4
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 clean, RESTful API.
29
+ - **Lightweight UI**: Fast, responsive, Jinja2 templates with server-side pagination, sorting, and search.
30
+ - **Attention Filters**: Highlight critical records (e.g. low stock, inactive users) requiring moderation attention.
31
+ - **Live Activity Badges**: "24h Activity" badges in headers and footers for real-time monitoring.
32
+ - **Custom System Logs**: Display a customizable activity feed on the main dashboard.
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ Install the package directly into your project:
39
+
40
+ ```bash
41
+ pip install fastapi-lite-admin
42
+ ```
43
+
44
+ For development/local setup, clone the repository and run:
45
+
46
+ ```bash
47
+ pip install -e ".[dev]"
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Quick Start & Usage
53
+
54
+ 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.
55
+
56
+ ### 1. Initialize the Admin Panel
57
+
58
+ Instantiate the `Admin` class and mount it to your `FastAPI` instance.
59
+
60
+ ```python
61
+ from fastapi import FastAPI
62
+ from fastapi_admin_lite import Admin
63
+
64
+ app = FastAPI()
65
+
66
+ admin = Admin(
67
+ title="Secure Control Panel", # Dashboard title
68
+ base_url="/admin", # URL prefix for the admin panel
69
+ enable_ui=True # Enable/disable Jinja-based UI
70
+ )
71
+
72
+ # Mount the admin router and views to your FastAPI app
73
+ admin.mount(app)
74
+ ```
75
+
76
+ This will automatically create and serve:
77
+ - The UI dashboard at `http://localhost:8000/admin`
78
+
79
+ ---
80
+
81
+ ## Registering Models (Adding Tables)
82
+
83
+ To add database tables to your admin panel, register your models using `admin.register()`.
84
+
85
+ ```python
86
+ from database import get_db # Your SQLAlchemy session dependency
87
+ from models import User
88
+
89
+ admin.register(
90
+ model=User,
91
+ get_db=get_db,
92
+ list_display=["id", "email", "is_active", "created_at"],
93
+ date_field="created_at",
94
+ attention_filter=(User.is_active == False),
95
+ readonly_fields=["created_at"],
96
+ config={"display_name": "System Users"}
97
+ )
98
+ ```
99
+
100
+ ### Registration Configuration Parameters
101
+
102
+ When calling `admin.register()`, you can configure how each model is represented:
103
+
104
+ | Parameter | Type | Required | Description |
105
+ | :--- | :--- | :--- | :--- |
106
+ | **`model`** | `Type[Any]` | **Yes** | The SQLAlchemy Declarative model class to generate CRUD operations for. |
107
+ | **`get_db`** | `Callable` | **Yes** | An async/sync generator yielding an active SQLAlchemy database session (`AsyncSession` or `Session`). |
108
+ | **`list_display`** | `List[str]` | No | List of field/column names to display as columns in the UI model list view. Defaults to all fields. |
109
+ | **`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. |
110
+ | **`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. |
111
+ | **`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`). |
112
+ | **`config`** | `Dict[str, Any]` | No | Dictionary containing extra settings. Supports `"display_name"` to override the sidebar label. |
113
+
114
+ ---
115
+
116
+ ## Initialization Configurations
117
+
118
+ The `Admin` class constructor supports the following parameters for customization:
119
+
120
+ | Parameter | Type | Default | Description |
121
+ | :--- | :--- | :--- | :--- |
122
+ | **`title`** | `str` | `"FastAPI Admin Lite"` | Customized title displayed in the UI header and dashboard. |
123
+ | **`base_url`** | `str` | `"/admin"` | URL prefix where the admin UI is served. |
124
+ | **`enable_ui`** | `bool` | `True` | Whether to serve the Jinja2 templates UI. If `False`, only the API routes are registered. |
125
+ | **`dependencies`** | `List[Any]` | `[]` | General list of FastAPI dependencies to apply to all admin routes. |
126
+ | **`auth_dependency`** | `Callable` | `None` | Dependency function for custom security gating (e.g., checking tokens or cookies). |
127
+ | **`permission_checker`**| `Callable` | `allow all` | Custom callable to restrict user roles. |
128
+ | **`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). |
129
+ | **`get_logs`** | `Callable` | `None` | An optional callable (async or sync) returning system logs to display on the dashboard activity log feed. |
130
+ | **`logs_config`** | `Dict[str, Any]` | `{"title": "System Activity", "columns": ["level", "timestamp", "message"]}` | Config dictionary to customize dashboard log columns and activity title. |
131
+
132
+ ---
133
+
134
+ ## Gating Access & Security
135
+
136
+ By default, the admin panel warns if no authentication is configured. You can gate the admin panel and its APIs using standard FastAPI dependencies:
137
+
138
+ ### 1. `auth_dependency`
139
+
140
+ Pass a dependency to `Admin` constructor that handles authentication.
141
+
142
+ ```python
143
+ from fastapi import Header, HTTPException
144
+
145
+ async def verify_admin_token(x_admin_token: str = Header(None)):
146
+ if x_admin_token != "super-secret-admin-token":
147
+ raise HTTPException(status_code=401, detail="Unauthorized")
148
+ return x_admin_token
149
+
150
+ admin = Admin(
151
+ title="Secure Admin",
152
+ auth_dependency=verify_admin_token
153
+ )
154
+ ```
155
+
156
+ ### 2. `permission_checker`
157
+
158
+ Restrict granular user roles with a custom callable:
159
+
160
+ ```python
161
+ async def check_permissions(user: Any = Depends(get_current_user)) -> bool:
162
+ return user.is_superuser
163
+
164
+ admin = Admin(
165
+ title="Staff Portal",
166
+ permission_checker=check_permissions
167
+ )
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Custom Dashboard Activity Logs
173
+
174
+ Configure a live activity log feed on the dashboard homepage:
175
+
176
+ ```python
177
+ async def fetch_system_logs():
178
+ # Fetch logs from a database table, file, or third-party service
179
+ return [
180
+ {"level": "info", "timestamp": "10:45 AM", "event": "User signup", "user": "alice@example.com"},
181
+ {"level": "error", "timestamp": "11:20 AM", "event": "Payment failed", "user": "bob@example.com"}
182
+ ]
183
+
184
+ admin = Admin(
185
+ title="Command Center",
186
+ get_logs=fetch_system_logs,
187
+ logs_config={
188
+ "title": "Recent Activity Feed",
189
+ "columns": ["level", "timestamp", "event", "user"]
190
+ }
191
+ )
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Running the Example Application
197
+
198
+ We package a complete working example inside the `/example` directory. To run it:
199
+
200
+ ```bash
201
+ # 1. Install dependencies with dev options
202
+ pip install -e ".[dev]"
203
+
204
+ # 2. Run the example application
205
+ python -m example.main
206
+ ```
207
+
208
+ 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.
209
+
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fastapi-lite-admin"
7
- version = "0.1.3"
7
+ version = "0.1.4"
8
8
  description = "A lightweight, pluggable admin panel for FastAPI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -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
- ```