Registry / web-framework / fastapi-injector

fastapi-injector

JSON →
library0.9.0pypypiunverified

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-injector
INSTALL
IMPORT
SIG · FASTAPI-INJECTOR
F
fastapi-injector
web-frameworkpythonv0.9.0
Install
1.7s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FastAPIInjector
from fastapi_injector import FastAPIInjector
from fastapi_injector import FastAPIInjector

Basic FastAPI app with injector module binding and route injection.

from fastapi import FastAPI, APIRouter from fastapi_injector import FastAPIInjector, Injected, request_injector from injector import Module, singleton, inject class MyModule(Module): def configure(self, binder): binder.bind(str, to='Hello, World!', scope=singleton) app = FastAPI() injector = FastAPIInjector(app, modules=[MyModule()]) @router.get('/') async def root(greeting: str = Injected(str)) -> dict: return {'message': greeting} app.include_router(router) if __name__ == '__main__': import uvicorn uvicorn.run(app)
Debug
Known issues
gotcha`request_injector` is a property on the app instance, not a standalone import. It must be accessed via `app.state.injector` or `request_injector` only inside a request context when using `AttachInjector` middleware.
fix
Use `from fastapi_injector import request_injector` and then `request_injector.get(SomeClass)` only within a request handler after calling `injector.attach_injector(app)`.
affects: 0.9.0
deprecatedThe `Injected` type hint from fastapi_injector is deprecated in favor of using `Depends` with a provider from injector. The direct use of `Injected` may be removed in future versions.
fix
Instead of `param: SomeClass = Injected(SomeClass)`, define a dependency function using `Depends` that gets the value from the injector's container.
affects: 0.9.0
breakingIn version 0.9.0, the `FastAPIInjector` class no longer automatically attaches the injector to the app's state. You must explicitly call `attach_injector()` method on the `FastAPIInjector` instance after creation.
fix
After creating `injector = FastAPIInjector(app, modules=[...])`, call `injector.attach_injector()` before the first request.
affects: 0.9.0
Upgrade
Version history
0.9.0latest on PyPI · released Oct 10, 2025
Audit
Dependencies
fastapirequiredRequired framework
injectorrequiredCore DI library
Agent activity
21 hits · last 30 days
node
18
Resources
fastapi-injector — pip install fastapi-injector · libregistry