Package-based route, listener, and task discovery for Litestar
Project description
Litestar Autowire
Domain package discovery for Litestar applications.
litestar-autowire lets a Litestar app treat each feature or bounded context as
a small Python package. Group the domain's controllers, listeners, and jobs
together, then wire the domain root into the app once.
Use it when your app has a domains/ package and each domain owns its Litestar
surface:
my_app/
domains/
accounts/
controllers.py
events.py
jobs.py
billing/
controllers.py
Installation
pip install litestar-autowire
Optional integrations:
pip install "litestar-autowire[dishka]"
pip install "litestar-autowire[queues]"
Quick Start
Define normal Litestar controllers inside a domain package:
# my_app/domains/accounts/controllers.py
from litestar import Controller, get
class AccountController(Controller):
path = "/accounts"
@get("/", sync_to_thread=False)
def list_accounts(self) -> dict[str, str]:
return {"status": "ok"}
Register the domain root once:
from litestar import Litestar
from litestar_autowire import AutowireConfig, AutowirePlugin
app = Litestar(
plugins=[
AutowirePlugin(
AutowireConfig(domain_packages=["my_app.domains"]),
)
],
)
Autowire checks the configured domain package root and its direct child domain packages for these module names:
- controllers:
controllers,routes,controller,route - listeners:
events,listeners - queue tasks:
jobs
With log_discovered=True, startup logs include the number of loaded
controllers, domains, listeners, and tasks. Debug logs include the controller
inventory grouped by domain.
Extensions
Built-in integrations use string aliases:
AutowireConfig(
domain_packages=["my_app.domains"],
extensions=["dishka", "queues"],
)
dishka: wrap discovered controllers in Dishka's Litestar router. Configure Dishka separately withsetup_dishka(...).queues: import task modules throughlitestar_queues.discover_tasks. ConfigureQueuePluginseparately in the Litestar app.
Unknown string aliases raise ValueError so typos do not silently disable an
integration. For custom behavior, pass an extension object instead:
from litestar.config.app import AppConfig
from litestar_autowire import AutowireConfig
class InventoryExtension:
name = "inventory"
def on_autowire(self, app_config: AppConfig, config: AutowireConfig) -> AppConfig:
app_config.state["autowire_domain_packages"] = config.domain_packages
return app_config
config = AutowireConfig(
domain_packages=["my_app.domains"],
extensions=[InventoryExtension()],
)
Custom extension names cannot reuse built-in names.
Development
uv sync --all-extras --dev
make lint
make test
make 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 litestar_autowire-0.1.0.tar.gz.
File metadata
- Download URL: litestar_autowire-0.1.0.tar.gz
- Upload date:
- Size: 151.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87032a256ed2ef15c3836306b09c1ff4a2954f89690b31b1c0dab6666aa533db
|
|
| MD5 |
b4795c6722b2e9fd87b45a38c9d744e9
|
|
| BLAKE2b-256 |
3fabb44aba530083c9734c0d6f59e0731aacaf9ebf215117d8f3b50f97fb7a27
|
Provenance
The following attestation bundles were made for litestar_autowire-0.1.0.tar.gz:
Publisher:
publish.yml on cofin/litestar-autowire
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_autowire-0.1.0.tar.gz -
Subject digest:
87032a256ed2ef15c3836306b09c1ff4a2954f89690b31b1c0dab6666aa533db - Sigstore transparency entry: 2043493000
- Sigstore integration time:
-
Permalink:
cofin/litestar-autowire@13b2a2fa279a10d84f8bd226541d22e1aff6473d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cofin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13b2a2fa279a10d84f8bd226541d22e1aff6473d -
Trigger Event:
release
-
Statement type:
File details
Details for the file litestar_autowire-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litestar_autowire-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4de5c72c8695035114af3ae02d062f6ea5ed2fc18c172e236b0226a843c5269b
|
|
| MD5 |
5a8585abeece488eb357f13dea439767
|
|
| BLAKE2b-256 |
a457eb9da96668fe7f3a139817e2952bd2b4fbcc534703c55af81bc6b3f7916d
|
Provenance
The following attestation bundles were made for litestar_autowire-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cofin/litestar-autowire
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_autowire-0.1.0-py3-none-any.whl -
Subject digest:
4de5c72c8695035114af3ae02d062f6ea5ed2fc18c172e236b0226a843c5269b - Sigstore transparency entry: 2043493038
- Sigstore integration time:
-
Permalink:
cofin/litestar-autowire@13b2a2fa279a10d84f8bd226541d22e1aff6473d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cofin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13b2a2fa279a10d84f8bd226541d22e1aff6473d -
Trigger Event:
release
-
Statement type: