https://github.com/noamsto/starlette-admin-litestar-plugin
https://github.com/noamsto/starlette-admin-litestar-plugin
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/noamsto/starlette-admin-litestar-plugin
- Owner: noamsto
- License: mit
- Created: 2025-01-31T20:53:23.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-03-13T15:21:57.000Z (about 1 month ago)
- Last Synced: 2025-03-13T16:30:10.147Z (about 1 month ago)
- Language: Python
- Size: 387 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-litestar - StarletteAdminPlugin - Integrates Starlette Admin with a Litestar application. (Third-Party Extensions / Admin)
README
# Starlette Admin Litestar Plugin
[](https://www.python.org)
[](https://litestar.dev)
[](https://github.com/astral-sh/uv)
[](https://github.com/astral-sh/ruff)
[](https://mypy-lang.org/)
[](https://github.com/pre-commit/pre-commit)A plugin that integrates [Starlette Admin](https://jowilf.github.io/starlette-admin/) with [Litestar](https://litestar.dev/), providing a powerful and flexible admin interface for your Litestar applications.
This project is inspired by and based on [SQLAdmin Litestar Plugin](https://github.com/peterschutt/sqladmin-litestar-plugin) by Peter Schutt.
## Features
- Seamless integration with [Starlette Admin](https://jowilf.github.io/starlette-admin/)
- Support for both sync and async SQLAlchemy engines
- Advanced Alchemy integration with UUID7 support
- Customizable admin interface
- Authentication support
- I18n support## Installation
```bash
pip install starlette-admin-litestar-plugin
```## Basic Usage
```python
from litestar import Litestar
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from starlette_admin.contrib.sqla import ModelView
from starlette_admin_litestar_plugin import StarlettAdminPluginConfig, StarletteAdminPlugin# Create engine and models
engine = create_async_engine("sqlite+aiosqlite:///:memory:")class Base(DeclarativeBase):
passclass Product(Base):
__tablename__ = "products"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
price: Mapped[int]# Configure admin
admin_config = StarlettAdminPluginConfig(
views=[ModelView(Product)],
engine=engine,
title="My Admin",
)# Create app
app = Litestar(
plugins=[StarletteAdminPlugin(starlette_admin_config=admin_config)]
)
```## Advanced Alchemy Support! Usage with UUID7 Models
```python
from advanced_alchemy.base import UUIDv7AuditBase
from pydantic import BaseModel, Field
from starlette_admin_litestar_plugin.ext.advanced_alchemy import UUIDModelView# Define model with UUID and audit
class Product(UUIDv7AuditBase):
__tablename__ = "products"
name: Mapped[str]
price: Mapped[int]# Optional: Add validation
class ProductInput(BaseModel):
name: str = Field(..., max_length=100)
price: int = Field(..., ge=0)# Configure admin with UUID support
admin_config = StarlettAdminPluginConfig(
views=[UUIDModelView(Product, pydantic_model=ProductInput)],
engine=engine,
title="Advanced Admin",
)app = Litestar(
plugins=[StarletteAdminPlugin(starlette_admin_config=admin_config)]
)
```See [advanced-alchemy](https://github.com/litestar-org/advanced-alchemy) repo for more info.
## Configuration Options
| Option | Type | Description | Default |
| ------------- | --------------------- | --------------------------- | -------- |
| views | Sequence[ModelView] | List of admin views | [] |
| engine | Engine \| AsyncEngine | SQLAlchemy engine | Required |
| title | str | Admin interface title | "Admin" |
| base_url | str | Base URL path | "/admin" |
| auth_provider | BaseAuthProvider | Authentication provider | None |
| i18n_config | I18nConfig | Internationalization config | None |For more configuration options and features, please refer to the [Starlette Admin documentation](https://jowilf.github.io/starlette-admin/).
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.