No project description provided
Project description
sqladmin-litestar-plugin
Overview
The SQLAdminPlugin
integrates SQLAdmin with a Litestar application.
Installation
To install the dependencies, run:
pip install sqladmin-litestar-plugin
Usage
To use the plugin, import the SQLAdminPlugin
class and pass it to the Litestar
application.
By default, the plugin will create a new admin interface at /admin
.
Example
from litestar import Litestar
from sqladmin import ModelView
from sqladmin_litestar_plugin import SQLAdminPlugin
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import declarative_base
engine = create_async_engine("sqlite+aiosqlite:///example.db")
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
name = Column(String)
class UserAdmin(ModelView, model=User):
column_list = [User.id, User.name]
async def on_startup() -> None:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all) # Create tables
admin = SQLAdminPlugin(views=[UserAdmin], engine=engine)
app = Litestar(plugins=[admin], on_startup=[on_startup])
Configuration
The SQLAdminPlugin
accepts the following arguments:
views
: A sequence ofModelView
classes to add to the admin app. EachModelView
class configures the interface for a SQL model.engine
: An SQLAlchemy engine to connect to your database.sessionmaker
: An SQLAlchemysessionmaker
instance used to manage sessions.base_url
: The base URL where the admin app will be hosted.title
: The title of the admin app, which appears in the browser's title bar and the header of the admin interface.logo_url
: The URL of the logo to display in the admin app, enhancing brand visibility.templates_dir
: The directory containing the Jinja2 templates for the admin interface, allowing for customization of the UI.middlewares
: A sequence of Starlette middlewares to add to the admin app, useful for handling requests or adding additional functionality.authentication_backend
: An authentication backend to secure the admin app, managing user authentication and authorization.
Views are not added to the admin app until the Litestar application is instantiated, so you can append views to the
views
list until this point.
TO DO
- An
AuthenticationBackend
that integrates with Litestar's session authentication.
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
Built Distribution
File details
Details for the file sqladmin_litestar_plugin-0.1.2.tar.gz
.
File metadata
- Download URL: sqladmin_litestar_plugin-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db61349948450bf90134ae9c8a1f075fdfdebd7ac17c78063cd2e8d6b065a1e8 |
|
MD5 | 76dc39fecae1314608ae079f1b2dce98 |
|
BLAKE2b-256 | 34732b8f4b364d4cb580e84751157f4563d36d720cbfd95c451949f0f7ffa623 |
File details
Details for the file sqladmin_litestar_plugin-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: sqladmin_litestar_plugin-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21e8f58ef5f8588bd5f380d0060d3cf061a891e0294467e2c361232ab7b0172 |
|
MD5 | 8dd0eac0e69d46480eb839a96b30aef7 |
|
BLAKE2b-256 | 6820962aa03a66f391cce0dc8b5c9e73d22e3d1ab414c4d25e355fb57a02754d |