Generic FastAPI + SQLAlchemy admin backend.
Project description
xladmin backend
xladmin-backend is the backend package published to PyPI as xladmin.
Important:
- package name on PyPI:
xladmin - Python import:
from xladmin import ... - monorepo: Artasov/xladmin
Public API
AdminConfig/ModelConfig/FieldConfigListFilterConfigBulkActionConfig/ObjectActionConfigModelsBlockHttpConfigcreate_router(...)
Compatibility aliases are kept:
Admin*config namescreate_admin_router(...)
Minimal Example
from xladmin import AdminConfig, HttpConfig, ModelConfig, create_router
from src.core.auth.dependencies import get_current_user
from src.core.db.session import get_db_session
from src.modules.identity.models import UserORM
config = AdminConfig(
models=(
ModelConfig(model=UserORM),
),
)
router = create_router(
HttpConfig(
registry=config,
get_db_session_dependency=get_db_session,
get_current_user_dependency=get_current_user,
is_allowed=lambda user: bool(user.is_staff),
),
)
ModelConfig(model=UserORM) is enough for a basic admin. The library derives default slug, title, search fields, and ordering from the ORM model.
Features
- list / detail / create / patch / delete endpoints
- bulk actions and object actions
- relation choices and relation filters
- overview metadata and model blocks
query_for_listand customsearch_query_builder- mode-specific form fields with
hidden_in_create/hidden_in_update - custom create defaults with
create_item_factory - delete preview for single and bulk delete
- RU / EN locale metadata for the frontend
Create And Update Fields
If a field should be visible only in one form mode, use hidden_in_create or hidden_in_update.
from xladmin import FieldConfig, ModelConfig
ModelConfig(
model=UserORM,
fields={
"password": FieldConfig(
input_kind="password",
hidden_in_update=True,
value_setter=set_user_password,
),
"new_password": FieldConfig(
input_kind="password",
hidden_in_create=True,
value_getter=lambda _user: "",
value_setter=set_user_password,
),
},
)
If create requires hidden service fields, use create_item_factory.
from xladmin import ModelConfig
def create_admin_user(payload, session, user):
del payload, session, user
return UserORM(
date_joined=AuthBase.now(),
secret_key=AuthBase.generate_secret_key(),
)
ModelConfig(
model=UserORM,
create_fields=("username", "email", "password"),
create_item_factory=create_admin_user,
)
Compatibility
FastAPI >=0.115,<1.0Pydantic >=2.9,<3.0SQLAlchemy >=2.0,<3.0Python >=3.12
Development
uv sync --extra dev
uv run pytest
uv run ruff check .
uv run mypy
uv run python -m build
uv run python -m twine check dist/*
Docs
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xladmin-0.3.0.tar.gz.
File metadata
- Download URL: xladmin-0.3.0.tar.gz
- Upload date:
- Size: 27.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
960e84d4277daa4e58cd263ba38cf593d82e2ea33b24ffd31f9d5d5d22ba985d
|
|
| MD5 |
1632f2179d13ee695b8f010a4942d5a2
|
|
| BLAKE2b-256 |
c2e08a826cdfb08eedc61a3af050d75bb8f155483051d091188f14f0626875cb
|
File details
Details for the file xladmin-0.3.0-py3-none-any.whl.
File metadata
- Download URL: xladmin-0.3.0-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b08703dd06327f615817cf6fdf72804c4400606e60e67514a522d5fac97bece1
|
|
| MD5 |
fd9596e348fc3f77cf12f0e8df82c5c0
|
|
| BLAKE2b-256 |
0efbd476719393c75b145d81a20ac1030d61b310652d153171a9ff149d88205b
|