Skip to main content

Starlette Admin plugin for LiteStar

Project description

Starlette Admin Litestar Plugin

Python Litestar uv Ruff Checked with mypy pre-commit

A plugin that integrates Starlette Admin with Litestar, providing a powerful and flexible admin interface for your Litestar applications.

This project is inspired by and based on SQLAdmin Litestar Plugin by Peter Schutt.

Features

  • Seamless integration with Starlette Admin
  • Support for both sync and async SQLAlchemy engines
  • Advanced Alchemy integration with UUID7 support
  • Customizable admin interface
  • Authentication support
  • I18n support

Installation

pip install starlette-admin-litestar-plugin

Basic Usage

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):
    pass

class 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

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 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.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_admin_litestar_plugin-0.3.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file starlette_admin_litestar_plugin-0.3.0.tar.gz.

File metadata

File hashes

Hashes for starlette_admin_litestar_plugin-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5a41d9a40714d43e788333a1e0264390e7cb93905225ee1e424e9d01217c6729
MD5 fb246b2dbbd237109a7f538b02476bd2
BLAKE2b-256 4517ca649991151d699ead4df1dec13c7947f25d9b7f06a14cdb8fdd7682ceb4

See more details on using hashes here.

File details

Details for the file starlette_admin_litestar_plugin-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for starlette_admin_litestar_plugin-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c772ec50a96aad1719b5d2125485e68fca50e26c6f68ef709e58ff061da2489f
MD5 8f8ce35a56d528d5988f925455ada744
BLAKE2b-256 6a8b1d1be708165cc372ab01a4b162ee722655d5ee1740f3836b5b2695834dc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page