Skip to content

cemrehancavdar/sqladmin-litestar

 
 

Repository files navigation

Build Status Publish Status Coverage Package version Supported Python versions


SQLAlchemy Admin for Litestar

SQLAdmin is a flexible Admin interface for SQLAlchemy models.

Main features include:


Documentation: https://aminalaee.dev/sqladmin

Source Code: https://github.com/cemrehancavdar/sqladmin-litestar

Original Source Code: https://github.com/aminalaee/sqladmin

Online Demo: Demo


Installation

Install using pip:

$ pip install sqladmin-litestar

This will install the full version of sqladmin with optional dependencies:

$ pip install "sqladmin-litestar[full]"

Screenshots

sqladmin-1

sqladmin-2

Quickstart

Let's define an example SQLAlchemy model:

from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import declarative_base


Base = declarative_base()
engine = create_engine(
    "sqlite:///example.db",
    connect_args={"check_same_thread": False},
)


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    name = Column(String)


Base.metadata.create_all(engine)  # Create tables

If you want to use SQLAdmin with Litestar:

from litestar import Litestar
from sqladmin import Admin, ModelView


app = Litestar()
admin = Admin(app, engine)


class UserAdmin(ModelView, model=User):
    column_list = [User.id, User.name]


admin.add_view(UserAdmin)

Now visiting /admin on your browser you can see the SQLAdmin interface.

Differences between SQLAdmin and SQLAdmin-Litestar

  1. Working with Custom Views

SQLAdmin-Litestar templates works sync, and handlers should be annotated.

 @expose("/report", methods=["GET"])
 async def report_page(self, request):
     return await self.templates.TemplateResponse(request, "report.html")
should be changed to
 @expose("/report", methods=["GET"])
 async def report_page(self, request) -> str:
     return self.templates.TemplateResponse(request, "report.html")

Related projects and inspirations

  • SQLAdmin The original SQLAdmin Repository
  • Flask-Admin Admin interface for Flask supporting different database backends and ORMs. This project has inspired SQLAdmin extensively and most of the features and configurations are implemented the same.
  • FastAPI-Admin Admin interface for FastAPI which works with TortoiseORM.
  • Dashboard Admin interface for ASGI frameworks which works with the orm package.

About

SQLAlchemy Admin for Litestar (original is for FastAPI and Starlette)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 88.7%
  • HTML 9.9%
  • JavaScript 1.4%