litestar-autowire
Skill15 starsChanged 2 months agoMITView on GitHub
Auto-activate for litestar_autowire, AutowirePlugin, AutowireConfig, domain_packages, AutowireIntegration, AutowireLoader, or clear_autowire_cache. Not for manual Router composition — use explicit routes.
- Installs packages
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- advanced-alchemySkill
- litestar-aiSkill
- litestar-buildSkill
- litestar-deploymentSkill
- litestar-emailSkill
- litestar-granianSkill
- litestar-htmxSkill
- litestar-mcpSkill
- litestar-queuesSkill
- litestar-saqSkill
- litestar-securitySkill
- litestarSkill
- litestar-styleguideSkill
- litestar-testingSkill
- litestar-viteSkill
- msgspecSkill
- polyfactorySkill
- pytest-databasesSkill
- sqlspecSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Use Autowire when the project already groups features into stable Python packages.
- Very specific: line 20
Import public APIs from litestar_autowire.
- Distinctive: line 21
Keep controllers and listeners in their owning domain package.
- Distinctive: line 22
Keep route handlers and listeners async when they perform I/O.
- Very specific: line 26
Call clear_autowire_cache() when tests create, replace, or remove modules.
- Very specific: line 99
Use config.integration_enabled(name) to check whether an integration with name is configured.
- Distinctive: line 143
Keep the default module names or configure explicit module-name tuples.
- Distinctive: line 146
Test discovery, error propagation, and cache isolation with the patterns in Testing.
- Distinctive: line 172
Do not suppress dependency import failures: Only an absent configured package or absent target component module is skipped.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
litestar-autowire
litestar-autowire 0.2.0 discovers Litestar controllers and event listeners
from domain packages. It can also load optional integration modules without
turning application setup into a central list of every domain component.
Use Autowire when the project already groups features into stable Python
packages. Keep manual Router and plugin composition when the app is small,
route registration is intentionally explicit, or packages do not follow a
consistent convention.
Code Style Rules
- Configure dotted package roots with
domain_packages. - Import public APIs from
litestar_autowire. - Keep controllers and listeners in their owning domain package.
- Keep route handlers and listeners async when they perform I/O.
- Configure third-party loaders via
integrations(DishkaIntegration(),QueuesIntegration()). - Configure Dishka and Litestar Queues separately; Autowire only discovers or wraps their domain-owned components.
- Call
clear_autowire_cache()when tests create, replace, or remove modules.
Quick Reference
Install
pip install litestar-autowire==0.2.0Install only the integrations already used by the project:
pip install "litestar-autowire[dishka]==0.2.0"
pip install "litestar-autowire[queues]==0.2.0"Domain layout
my_app/
└── domains/
├── accounts/
│ ├── controllers.py
│ ├── events.py
│ └── jobs.py
└── billing/
└── routes.pyRegular packages and PEP 420 namespace packages are supported. Autowire checks the configured root and each direct child package. Read Discovery before changing module conventions or debugging a missing component.
App setup
from litestar import Litestar
from litestar_autowire import AutowireConfig, AutowirePlugin
autowire = AutowirePlugin(
AutowireConfig(domain_packages=["my_app.domains"]),
)
app = Litestar(plugins=[autowire])The default component modules are:
| Component | Module names | Enabled |
| Controllers | controllers, routes, controller, route | Yes |
| Event listeners | events, listeners | Yes |
| Litestar Queues tasks | jobs | Only with integrations=["queues"] |
AutowireConfig fields (all constructor arguments are keyword-only):
| Field | Default | Contract |
domain_packages | () | str | Iterable[str] normalized to tuple[str, ...] |
integrations | () | Built-in names ("dishka", "queues") or AutowireIntegration objects |
discover_controllers | True | Register discovered Controller subclasses |
discover_listeners | True | Register discovered EventListener instances |
controller_modules | ("controllers", "routes", "controller", "route") | str | Iterable[str] normalized to tuple[str, ...] |
listener_modules | ("events", "listeners") | str | Iterable[str] normalized to tuple[str, ...] |
task_modules | ("jobs",) | str | Iterable[str] normalized to tuple[str, ...] |
router_class | None | Optional router wrapper (litestar.Router or compatible type) |
before_request | None | Optional hook attached to the wrapper router |
after_response | None | Optional hook attached to the wrapper router |
force_reload_tasks | False | Passed to litestar_queues.discover_tasks(force_reload=...) |
log_discovered | True | Defer discovery summary logs to the Litestar startup hook |
Use config.integration_enabled(name) to check whether an integration with name is configured.
Customize module names without changing the domain layout:
config = AutowireConfig(
domain_packages=["my_app.domains"],
controller_modules=["http"],
listener_modules=["subscribers"],
discover_listeners=False,
)Router selection
By default, discovered controller classes are appended directly to
AppConfig.route_handlers. Set router_class=Router when the project needs a
wrapper for router-level before_request or after_response hooks:
from litestar import Router
from litestar_autowire import AutowireConfig
config = AutowireConfig(
domain_packages=["my_app.domains"],
router_class=Router,
before_request=set_request_context,
after_response=record_response,
)The wrapper is constructed with path="/", the discovered controller classes,
and the configured hooks. Use integrations=["dishka"] instead when the
project already uses Dishka and needs DishkaRouter. See
Integrations.
<workflow>Workflow
- Inspect the project layout and confirm domains are importable package roots.
- Choose Autowire only when domain packages follow consistent controller or listener module conventions.
- Register one
AutowirePlugin(AutowireConfig(...))in the app plugin list. - Keep the default module names or configure explicit module-name tuples.
- Enable only integrations already present in the project stack.
- Configure Dishka or Litestar Queues through their own application plugins.
- Test discovery, error propagation, and cache isolation with the patterns in Testing.
</workflow><guardrails>Guardrails
- Do not describe Autowire as recursive domain discovery. It discovers the configured root and direct feature children; component modules may themselves contain importable leaf modules.
- Do not claim arbitrary route-handler discovery. Autowire registers
Controllersubclasses andEventListenerobjects. - Do not invent registry or discovered-item wrapper types. Autowire 0.2.0
exports
AutowirePlugin,AutowireConfig,AutowireContext,AutowireIntegration,AutowireLoader,DishkaIntegration,QueuesIntegration,clear_autowire_cache,discover_controllers,discover_feature_packages,discover_listeners,discover_queue_tasks,find_controllers_in_module, andfind_listeners_in_module. There is noAutowireRegistry,DomainMetadata,DiscoveredCLI,DiscoveredController,DiscoveredJob,DiscoveredProvider,DiscoveredSchema,DiscoveredSignal,LitestarQueuesIntegration, orSAQIntegration(useAutowireLoaderfor SAQ or custom module registries). - Do not imply queue tasks are enabled by default. The
queuesintegration must be selected and its optional dependency installed. - Do not suppress dependency import failures. Only an absent configured package or absent target component module is skipped.
- Do not use both a custom
router_classand expect Dishka to replace it.DishkaIntegrationpreserves an already selected router class. - Do not hide
FromDishka[...]types underif TYPE_CHECKING:whenfrom __future__ import annotationsis enabled in controller modules.DishkaRouter.registercallstyping.get_type_hints()on each controller handler at registration time, which raisesNameErrorif injected types are absent from runtime module globals or defined only in a function scope. - Do not reuse a
Controllerclass across unit tests afterDishkaRouterregistration without restoringget_route_handlers.DishkaRouter.registermonkey-patchesControllerSubclass.get_route_handlersin-place on the class. - Do not give custom integrations the names
dishkaorqueues. Built-in name collisions fail during configuration. - Do not reuse stale discovery state in tests or reload tooling. Clear the process-local caches before rediscovery.
</guardrails><validation>Validation Checkpoint
domain_packagescontains importable dotted package roots.- The configured roots and component module names match the source layout.
- Controller classes are defined in the discovered module, not merely re-exported into it.
- Queue task discovery is enabled only with the Queues extra and integration.
- Dishka and Litestar Queues retain their own application configuration.
- Controller modules wired with Dishka keep
FromDishka[...]dependency types importable at runtime rather than insideif TYPE_CHECKING:underfrom __future__ import annotations. - Custom integrations satisfy
AutowireIntegrationand use unique names. - Router hooks are paired with a compatible
router_class. - Tests call
clear_autowire_cache()around dynamic module changes and restoreController.get_route_handlerswhen reusing controllers with Dishka. - Missing dependency imports still fail instead of silently dropping a domain.
</validation><example>Example
from litestar import Controller, get
class AccountController(Controller):
path = "/accounts"
@get()
async def list_accounts(self) -> list[dict[str, str]]:
return [{"name": "primary"}]from litestar import Litestar
from litestar_autowire import AutowireConfig, AutowirePlugin
app = Litestar(
plugins=[
AutowirePlugin(
AutowireConfig(
domain_packages=["my_app.domains"],
discover_controllers=True,
discover_listeners=True,
)
)
],
)Autowire imports my_app.domains.accounts.controllers, registers
AccountController, and checks the configured listener module names. It does
not load jobs.py until the queues integration is selected.
</example>References Index
- Discovery — package traversal, PEP 420 behavior, component selection, caches, and import failures
- Integrations — custom integrations,
AutowireLoader, router selection, Dishka, and Litestar Queues - Testing — deterministic cache isolation and package-discovery tests
- Litestar Routing — controller and manual router composition
- Litestar Plugins — application plugin wiring
- Litestar DI — built-in DI and Dishka selection
- Litestar Queues — queue configuration, tasks, and workers
- Litestar Testing — Litestar test clients and dependency overrides
Official References
- https://github.com/cofin/litestar-autowire/releases/tag/v0.2.0
- https://github.com/cofin/litestar-autowire/tree/v0.2.0/litestar_autowire
- https://github.com/cofin/litestar-autowire/blob/v0.2.0/tests/unit/test_autowire_plugin.py
Shared Styleguide Baseline
- General
- Python
- Litestar
- Testing
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

