Integrates python-injector with FastAPI for dependency injection. Current version: 0.9.0. Supports Python 3.10+. Releases are infrequent; last release 2023.
pip install fastapi-injectorVerified import paths — ran on the pinned version, not inferred.
Basic FastAPI app with injector module binding and route injection.
Use `from fastapi_injector import request_injector` and then `request_injector.get(SomeClass)` only within a request handler after calling `injector.attach_injector(app)`.
Instead of `param: SomeClass = Injected(SomeClass)`, define a dependency function using `Depends` that gets the value from the injector's container.
After creating `injector = FastAPIInjector(app, modules=[...])`, call `injector.attach_injector()` before the first request.