litestar-admin 0.1.0__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.
- litestar_admin-0.1.0/PKG-INFO +249 -0
- litestar_admin-0.1.0/README.md +194 -0
- litestar_admin-0.1.0/pyproject.toml +354 -0
- litestar_admin-0.1.0/src/litestar_admin/__init__.py +35 -0
- litestar_admin-0.1.0/src/litestar_admin/audit/__init__.py +102 -0
- litestar_admin-0.1.0/src/litestar_admin/audit/database.py +294 -0
- litestar_admin-0.1.0/src/litestar_admin/audit/logger.py +511 -0
- litestar_admin-0.1.0/src/litestar_admin/audit/middleware.py +342 -0
- litestar_admin-0.1.0/src/litestar_admin/audit/models.py +162 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/__init__.py +48 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/jwt.py +518 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/models.py +377 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/password.py +321 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/password_reset.py +386 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/protocols.py +125 -0
- litestar_admin-0.1.0/src/litestar_admin/auth/session.py +137 -0
- litestar_admin-0.1.0/src/litestar_admin/config.py +212 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/__init__.py +12 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/oauth/__init__.py +72 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/oauth/backend.py +847 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/oauth/config.py +277 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/providers/__init__.py +51 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/providers/http_api.py +333 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/providers/in_memory.py +354 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/providers/json_file.py +341 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/sqladmin/__init__.py +63 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/sqladmin/bridge.py +424 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/storages/__init__.py +122 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/storages/backend.py +668 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/storages/config.py +310 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/storages/thumbnails.py +504 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/storages/utils.py +358 -0
- litestar_admin-0.1.0/src/litestar_admin/contrib/vite/__init__.py +5 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/__init__.py +196 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/auth.py +345 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/bulk.py +327 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/config.py +160 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/custom_views.py +1382 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/dashboard.py +327 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/export.py +621 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/files.py +861 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/import_data.py +1479 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/models.py +663 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/oauth.py +171 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/relationships.py +524 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/settings.py +432 -0
- litestar_admin-0.1.0/src/litestar_admin/controllers/users.py +1171 -0
- litestar_admin-0.1.0/src/litestar_admin/discovery.py +389 -0
- litestar_admin-0.1.0/src/litestar_admin/fields/__init__.py +104 -0
- litestar_admin-0.1.0/src/litestar_admin/fields/file.py +446 -0
- litestar_admin-0.1.0/src/litestar_admin/fields/rich_text.py +295 -0
- litestar_admin-0.1.0/src/litestar_admin/fields/sanitize.py +205 -0
- litestar_admin-0.1.0/src/litestar_admin/guards/__init__.py +52 -0
- litestar_admin-0.1.0/src/litestar_admin/guards/permissions.py +399 -0
- litestar_admin-0.1.0/src/litestar_admin/logging.py +346 -0
- litestar_admin-0.1.0/src/litestar_admin/middleware/__init__.py +65 -0
- litestar_admin-0.1.0/src/litestar_admin/middleware/auth.py +144 -0
- litestar_admin-0.1.0/src/litestar_admin/middleware/ratelimit.py +833 -0
- litestar_admin-0.1.0/src/litestar_admin/plugin.py +508 -0
- litestar_admin-0.1.0/src/litestar_admin/py.typed +0 -0
- litestar_admin-0.1.0/src/litestar_admin/registry.py +335 -0
- litestar_admin-0.1.0/src/litestar_admin/relationships/__init__.py +32 -0
- litestar_admin-0.1.0/src/litestar_admin/relationships/detector.py +476 -0
- litestar_admin-0.1.0/src/litestar_admin/relationships/types.py +116 -0
- litestar_admin-0.1.0/src/litestar_admin/service.py +909 -0
- litestar_admin-0.1.0/src/litestar_admin/settings/__init__.py +63 -0
- litestar_admin-0.1.0/src/litestar_admin/settings/models.py +171 -0
- litestar_admin-0.1.0/src/litestar_admin/settings/service.py +365 -0
- litestar_admin-0.1.0/src/litestar_admin/views/__init__.py +27 -0
- litestar_admin-0.1.0/src/litestar_admin/views/action.py +392 -0
- litestar_admin-0.1.0/src/litestar_admin/views/admin_view.py +174 -0
- litestar_admin-0.1.0/src/litestar_admin/views/base.py +754 -0
- litestar_admin-0.1.0/src/litestar_admin/views/custom.py +674 -0
- litestar_admin-0.1.0/src/litestar_admin/views/embed.py +273 -0
- litestar_admin-0.1.0/src/litestar_admin/views/link.py +172 -0
- litestar_admin-0.1.0/src/litestar_admin/views/model.py +39 -0
- litestar_admin-0.1.0/src/litestar_admin/views/page.py +244 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: litestar-admin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modern admin panel framework for Litestar with Cloudflare-inspired UI
|
|
5
|
+
Keywords: litestar,admin,dashboard,crud,sqlalchemy,admin-panel
|
|
6
|
+
Author: Jacob Coffee
|
|
7
|
+
Author-email: Jacob Coffee <jacob@z7x.org>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: AsyncIO
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Dist: litestar>=2.0.0
|
|
25
|
+
Requires-Dist: advanced-alchemy>=0.10.0
|
|
26
|
+
Requires-Dist: sqlalchemy[asyncio]>=2.0.0
|
|
27
|
+
Requires-Dist: aiofiles>=25.1.0
|
|
28
|
+
Requires-Dist: litestar-admin[jwt,oauth,sqladmin,redis,structlog,auth,storage,excel,sanitize] ; extra == 'all'
|
|
29
|
+
Requires-Dist: passlib[argon2]>=1.7.4 ; extra == 'auth'
|
|
30
|
+
Requires-Dist: openpyxl>=3.1.0 ; extra == 'excel'
|
|
31
|
+
Requires-Dist: pyjwt>=2.8.0 ; extra == 'jwt'
|
|
32
|
+
Requires-Dist: litestar-oauth>=0.1.0 ; extra == 'oauth'
|
|
33
|
+
Requires-Dist: redis>=5.0.0 ; extra == 'redis'
|
|
34
|
+
Requires-Dist: nh3>=0.2.0 ; extra == 'sanitize'
|
|
35
|
+
Requires-Dist: sqladmin-litestar-plugin>=0.1.0 ; extra == 'sqladmin'
|
|
36
|
+
Requires-Dist: litestar-storages>=0.1.0 ; extra == 'storage'
|
|
37
|
+
Requires-Dist: pillow>=10.0.0 ; extra == 'storage'
|
|
38
|
+
Requires-Dist: structlog>=24.1.0 ; extra == 'structlog'
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Project-URL: Documentation, https://jacobcoffee.github.io/litestar-admin
|
|
41
|
+
Project-URL: Homepage, https://github.com/JacobCoffee/litestar-admin
|
|
42
|
+
Project-URL: Issues, https://github.com/JacobCoffee/litestar-admin/issues
|
|
43
|
+
Project-URL: Repository, https://github.com/JacobCoffee/litestar-admin
|
|
44
|
+
Provides-Extra: all
|
|
45
|
+
Provides-Extra: auth
|
|
46
|
+
Provides-Extra: excel
|
|
47
|
+
Provides-Extra: jwt
|
|
48
|
+
Provides-Extra: oauth
|
|
49
|
+
Provides-Extra: redis
|
|
50
|
+
Provides-Extra: sanitize
|
|
51
|
+
Provides-Extra: sqladmin
|
|
52
|
+
Provides-Extra: storage
|
|
53
|
+
Provides-Extra: structlog
|
|
54
|
+
Description-Content-Type: text/markdown
|
|
55
|
+
|
|
56
|
+
# litestar-admin
|
|
57
|
+
|
|
58
|
+
[](https://github.com/JacobCoffee/litestar-admin/actions/workflows/ci.yml)
|
|
59
|
+
[](https://badge.fury.io/py/litestar-admin)
|
|
60
|
+
[](https://pypi.org/project/litestar-admin/)
|
|
61
|
+
[](https://opensource.org/licenses/MIT)
|
|
62
|
+
|
|
63
|
+
**Modern admin panel framework for Litestar applications with a Cloudflare-inspired UI.**
|
|
64
|
+
|
|
65
|
+
litestar-admin provides a production-ready admin interface for managing SQLAlchemy models in Litestar applications, featuring:
|
|
66
|
+
|
|
67
|
+
- **Cloudflare Dashboard-inspired UI** - Modern dark theme with clean card layouts
|
|
68
|
+
- **Full CRUD Operations** - Create, read, update, delete with bulk actions
|
|
69
|
+
- **RBAC Authorization** - Role-based access control with granular permissions
|
|
70
|
+
- **Audit Logging** - Track all admin actions for compliance
|
|
71
|
+
- **SQLAlchemy Integration** - Works with SQLAlchemy 2.x and Advanced-Alchemy
|
|
72
|
+
- **Auto-discovery** - Automatically discovers and registers models
|
|
73
|
+
- **JWT & OAuth2 Authentication** - Flexible, pluggable auth backends
|
|
74
|
+
- **Static Export Frontend** - Next.js frontend with no runtime Node.js required
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Basic installation
|
|
80
|
+
pip install litestar-admin
|
|
81
|
+
|
|
82
|
+
# With JWT authentication
|
|
83
|
+
pip install litestar-admin[jwt]
|
|
84
|
+
|
|
85
|
+
# With OAuth support
|
|
86
|
+
pip install litestar-admin[oauth]
|
|
87
|
+
|
|
88
|
+
# With sqladmin bridge
|
|
89
|
+
pip install litestar-admin[sqladmin]
|
|
90
|
+
|
|
91
|
+
# All extras
|
|
92
|
+
pip install litestar-admin[all]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Quick Start
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from litestar import Litestar
|
|
99
|
+
from litestar_admin import AdminPlugin, AdminConfig, ModelView
|
|
100
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
101
|
+
|
|
102
|
+
# Define your models
|
|
103
|
+
class Base(DeclarativeBase):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
class User(Base):
|
|
107
|
+
__tablename__ = "users"
|
|
108
|
+
|
|
109
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
110
|
+
email: Mapped[str] = mapped_column(unique=True)
|
|
111
|
+
name: Mapped[str]
|
|
112
|
+
|
|
113
|
+
# Create admin views
|
|
114
|
+
class UserAdmin(ModelView, model=User):
|
|
115
|
+
column_list = ["id", "email", "name"]
|
|
116
|
+
column_searchable_list = ["email", "name"]
|
|
117
|
+
can_delete = False # Disable deletion
|
|
118
|
+
|
|
119
|
+
# Create the app
|
|
120
|
+
app = Litestar(
|
|
121
|
+
plugins=[
|
|
122
|
+
AdminPlugin(
|
|
123
|
+
config=AdminConfig(
|
|
124
|
+
title="My Admin",
|
|
125
|
+
views=[UserAdmin],
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
]
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Configuration
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from litestar_admin import AdminConfig
|
|
136
|
+
from litestar_admin.auth import JWTAuthBackend
|
|
137
|
+
|
|
138
|
+
config = AdminConfig(
|
|
139
|
+
# Basic settings
|
|
140
|
+
title="My Admin Panel",
|
|
141
|
+
base_url="/admin",
|
|
142
|
+
theme="dark", # or "light"
|
|
143
|
+
|
|
144
|
+
# Authentication
|
|
145
|
+
auth_backend=JWTAuthBackend(
|
|
146
|
+
secret_key="your-secret-key",
|
|
147
|
+
algorithm="HS256",
|
|
148
|
+
),
|
|
149
|
+
|
|
150
|
+
# Model views
|
|
151
|
+
views=[UserAdmin, PostAdmin],
|
|
152
|
+
auto_discover=True, # Auto-discover models
|
|
153
|
+
|
|
154
|
+
# Rate limiting
|
|
155
|
+
rate_limit_enabled=True,
|
|
156
|
+
rate_limit_requests=100,
|
|
157
|
+
rate_limit_window_seconds=60,
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Model Views
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from litestar_admin import ModelView
|
|
165
|
+
|
|
166
|
+
class UserAdmin(ModelView, model=User):
|
|
167
|
+
# Display settings
|
|
168
|
+
name = "User"
|
|
169
|
+
name_plural = "Users"
|
|
170
|
+
icon = "user"
|
|
171
|
+
category = "User Management"
|
|
172
|
+
|
|
173
|
+
# Column configuration
|
|
174
|
+
column_list = ["id", "email", "name", "created_at"]
|
|
175
|
+
column_exclude_list = ["password_hash"]
|
|
176
|
+
column_searchable_list = ["email", "name"]
|
|
177
|
+
column_sortable_list = ["id", "email", "created_at"]
|
|
178
|
+
column_default_sort = ("created_at", "desc")
|
|
179
|
+
|
|
180
|
+
# Form configuration
|
|
181
|
+
form_columns = ["email", "name"]
|
|
182
|
+
form_excluded_columns = ["id", "created_at"]
|
|
183
|
+
|
|
184
|
+
# Permissions
|
|
185
|
+
can_create = True
|
|
186
|
+
can_edit = True
|
|
187
|
+
can_delete = False
|
|
188
|
+
can_export = True
|
|
189
|
+
|
|
190
|
+
# Pagination
|
|
191
|
+
page_size = 25
|
|
192
|
+
page_size_options = [10, 25, 50, 100]
|
|
193
|
+
|
|
194
|
+
# Custom access control
|
|
195
|
+
async def is_accessible(self, connection) -> bool:
|
|
196
|
+
user = connection.user
|
|
197
|
+
return user and user.is_admin
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## RBAC Guards
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from litestar_admin.guards import require_permission, Permission
|
|
204
|
+
|
|
205
|
+
@get("/admin/users", guards=[require_permission(Permission.MODELS_READ)])
|
|
206
|
+
async def list_users() -> list[User]:
|
|
207
|
+
...
|
|
208
|
+
|
|
209
|
+
@post("/admin/users", guards=[require_permission(Permission.MODELS_WRITE)])
|
|
210
|
+
async def create_user(data: UserCreate) -> User:
|
|
211
|
+
...
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Development
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Clone the repository
|
|
218
|
+
git clone https://github.com/JacobCoffee/litestar-admin.git
|
|
219
|
+
cd litestar-admin
|
|
220
|
+
|
|
221
|
+
# Install development dependencies
|
|
222
|
+
make dev
|
|
223
|
+
|
|
224
|
+
# Run tests
|
|
225
|
+
make test
|
|
226
|
+
|
|
227
|
+
# Run linting
|
|
228
|
+
make lint
|
|
229
|
+
|
|
230
|
+
# Build frontend
|
|
231
|
+
make frontend
|
|
232
|
+
|
|
233
|
+
# Build documentation
|
|
234
|
+
make docs
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Documentation
|
|
238
|
+
|
|
239
|
+
Full documentation is available at [jacobcoffee.github.io/litestar-admin](https://jacobcoffee.github.io/litestar-admin).
|
|
240
|
+
|
|
241
|
+
## Related Projects
|
|
242
|
+
|
|
243
|
+
- [litestar](https://github.com/litestar-org/litestar) - The ASGI framework
|
|
244
|
+
- [advanced-alchemy](https://github.com/jolt-org/advanced-alchemy) - SQLAlchemy toolkit
|
|
245
|
+
- [sqladmin-litestar-plugin](https://github.com/peterschutt/sqladmin-litestar-plugin) - SQLAdmin bridge
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# litestar-admin
|
|
2
|
+
|
|
3
|
+
[](https://github.com/JacobCoffee/litestar-admin/actions/workflows/ci.yml)
|
|
4
|
+
[](https://badge.fury.io/py/litestar-admin)
|
|
5
|
+
[](https://pypi.org/project/litestar-admin/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
**Modern admin panel framework for Litestar applications with a Cloudflare-inspired UI.**
|
|
9
|
+
|
|
10
|
+
litestar-admin provides a production-ready admin interface for managing SQLAlchemy models in Litestar applications, featuring:
|
|
11
|
+
|
|
12
|
+
- **Cloudflare Dashboard-inspired UI** - Modern dark theme with clean card layouts
|
|
13
|
+
- **Full CRUD Operations** - Create, read, update, delete with bulk actions
|
|
14
|
+
- **RBAC Authorization** - Role-based access control with granular permissions
|
|
15
|
+
- **Audit Logging** - Track all admin actions for compliance
|
|
16
|
+
- **SQLAlchemy Integration** - Works with SQLAlchemy 2.x and Advanced-Alchemy
|
|
17
|
+
- **Auto-discovery** - Automatically discovers and registers models
|
|
18
|
+
- **JWT & OAuth2 Authentication** - Flexible, pluggable auth backends
|
|
19
|
+
- **Static Export Frontend** - Next.js frontend with no runtime Node.js required
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Basic installation
|
|
25
|
+
pip install litestar-admin
|
|
26
|
+
|
|
27
|
+
# With JWT authentication
|
|
28
|
+
pip install litestar-admin[jwt]
|
|
29
|
+
|
|
30
|
+
# With OAuth support
|
|
31
|
+
pip install litestar-admin[oauth]
|
|
32
|
+
|
|
33
|
+
# With sqladmin bridge
|
|
34
|
+
pip install litestar-admin[sqladmin]
|
|
35
|
+
|
|
36
|
+
# All extras
|
|
37
|
+
pip install litestar-admin[all]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from litestar import Litestar
|
|
44
|
+
from litestar_admin import AdminPlugin, AdminConfig, ModelView
|
|
45
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
46
|
+
|
|
47
|
+
# Define your models
|
|
48
|
+
class Base(DeclarativeBase):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
class User(Base):
|
|
52
|
+
__tablename__ = "users"
|
|
53
|
+
|
|
54
|
+
id: Mapped[int] = mapped_column(primary_key=True)
|
|
55
|
+
email: Mapped[str] = mapped_column(unique=True)
|
|
56
|
+
name: Mapped[str]
|
|
57
|
+
|
|
58
|
+
# Create admin views
|
|
59
|
+
class UserAdmin(ModelView, model=User):
|
|
60
|
+
column_list = ["id", "email", "name"]
|
|
61
|
+
column_searchable_list = ["email", "name"]
|
|
62
|
+
can_delete = False # Disable deletion
|
|
63
|
+
|
|
64
|
+
# Create the app
|
|
65
|
+
app = Litestar(
|
|
66
|
+
plugins=[
|
|
67
|
+
AdminPlugin(
|
|
68
|
+
config=AdminConfig(
|
|
69
|
+
title="My Admin",
|
|
70
|
+
views=[UserAdmin],
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
]
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from litestar_admin import AdminConfig
|
|
81
|
+
from litestar_admin.auth import JWTAuthBackend
|
|
82
|
+
|
|
83
|
+
config = AdminConfig(
|
|
84
|
+
# Basic settings
|
|
85
|
+
title="My Admin Panel",
|
|
86
|
+
base_url="/admin",
|
|
87
|
+
theme="dark", # or "light"
|
|
88
|
+
|
|
89
|
+
# Authentication
|
|
90
|
+
auth_backend=JWTAuthBackend(
|
|
91
|
+
secret_key="your-secret-key",
|
|
92
|
+
algorithm="HS256",
|
|
93
|
+
),
|
|
94
|
+
|
|
95
|
+
# Model views
|
|
96
|
+
views=[UserAdmin, PostAdmin],
|
|
97
|
+
auto_discover=True, # Auto-discover models
|
|
98
|
+
|
|
99
|
+
# Rate limiting
|
|
100
|
+
rate_limit_enabled=True,
|
|
101
|
+
rate_limit_requests=100,
|
|
102
|
+
rate_limit_window_seconds=60,
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Model Views
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from litestar_admin import ModelView
|
|
110
|
+
|
|
111
|
+
class UserAdmin(ModelView, model=User):
|
|
112
|
+
# Display settings
|
|
113
|
+
name = "User"
|
|
114
|
+
name_plural = "Users"
|
|
115
|
+
icon = "user"
|
|
116
|
+
category = "User Management"
|
|
117
|
+
|
|
118
|
+
# Column configuration
|
|
119
|
+
column_list = ["id", "email", "name", "created_at"]
|
|
120
|
+
column_exclude_list = ["password_hash"]
|
|
121
|
+
column_searchable_list = ["email", "name"]
|
|
122
|
+
column_sortable_list = ["id", "email", "created_at"]
|
|
123
|
+
column_default_sort = ("created_at", "desc")
|
|
124
|
+
|
|
125
|
+
# Form configuration
|
|
126
|
+
form_columns = ["email", "name"]
|
|
127
|
+
form_excluded_columns = ["id", "created_at"]
|
|
128
|
+
|
|
129
|
+
# Permissions
|
|
130
|
+
can_create = True
|
|
131
|
+
can_edit = True
|
|
132
|
+
can_delete = False
|
|
133
|
+
can_export = True
|
|
134
|
+
|
|
135
|
+
# Pagination
|
|
136
|
+
page_size = 25
|
|
137
|
+
page_size_options = [10, 25, 50, 100]
|
|
138
|
+
|
|
139
|
+
# Custom access control
|
|
140
|
+
async def is_accessible(self, connection) -> bool:
|
|
141
|
+
user = connection.user
|
|
142
|
+
return user and user.is_admin
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## RBAC Guards
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from litestar_admin.guards import require_permission, Permission
|
|
149
|
+
|
|
150
|
+
@get("/admin/users", guards=[require_permission(Permission.MODELS_READ)])
|
|
151
|
+
async def list_users() -> list[User]:
|
|
152
|
+
...
|
|
153
|
+
|
|
154
|
+
@post("/admin/users", guards=[require_permission(Permission.MODELS_WRITE)])
|
|
155
|
+
async def create_user(data: UserCreate) -> User:
|
|
156
|
+
...
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Clone the repository
|
|
163
|
+
git clone https://github.com/JacobCoffee/litestar-admin.git
|
|
164
|
+
cd litestar-admin
|
|
165
|
+
|
|
166
|
+
# Install development dependencies
|
|
167
|
+
make dev
|
|
168
|
+
|
|
169
|
+
# Run tests
|
|
170
|
+
make test
|
|
171
|
+
|
|
172
|
+
# Run linting
|
|
173
|
+
make lint
|
|
174
|
+
|
|
175
|
+
# Build frontend
|
|
176
|
+
make frontend
|
|
177
|
+
|
|
178
|
+
# Build documentation
|
|
179
|
+
make docs
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Documentation
|
|
183
|
+
|
|
184
|
+
Full documentation is available at [jacobcoffee.github.io/litestar-admin](https://jacobcoffee.github.io/litestar-admin).
|
|
185
|
+
|
|
186
|
+
## Related Projects
|
|
187
|
+
|
|
188
|
+
- [litestar](https://github.com/litestar-org/litestar) - The ASGI framework
|
|
189
|
+
- [advanced-alchemy](https://github.com/jolt-org/advanced-alchemy) - SQLAlchemy toolkit
|
|
190
|
+
- [sqladmin-litestar-plugin](https://github.com/peterschutt/sqladmin-litestar-plugin) - SQLAdmin bridge
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT License - see [LICENSE](LICENSE) for details.
|