Registry / web-framework / fastapi-injectable

fastapi-injectable

JSON →
library1.4.7pypypi✓ verified 85d ago

Use FastAPI's Depends() anywhere — in CLI tools, Celery tasks, background workers, and more. No refactoring needed. Current version: 1.4.7. Python >=3.10. Active development.

pip install fastapi-injectable
INSTALL
IMPORT
SIG · FASTAPI-INJECTABLE
F
fastapi-injectable
web-frameworkpythonv1.4.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

get_injected_obj
from fastapi_injectable import get_injected_obj
from fastapi_injectable.util import get_injected_obj
The public API is at package level, not under util.
async_get_injected_obj
from fastapi_injectable import async_get_injected_obj
from fastapi_injectable.util import async_get_injected_obj
Use the top-level import for async variant.
Injectable
from fastapi_injectable import Injectable
from fastapi_injectable.decorator import Injectable
Injectable class is exposed at package level.

Inject FastAPI-style dependencies anywhere, even outside an async context.

from fastapi import Depends from fastapi_injectable import get_injected_obj from typing import Annotated async def get_db() -> str: return "db_session" DepDB = Annotated[str, Depends(get_db)] # Use in a non-FastAPI context (e.g., Celery task) def worker(dep: DepDB) -> None: print(dep) # Inject dependencies outside FastAPI obj = get_injected_obj(worker) print(obj)
Debug
Known issues
gotchaget_injected_obj() can fail with 'event loop already running' if called from an async context like an async callback or Kafka consumer. Use async_get_injected_obj() instead when already inside a running event loop.
fix
Replace get_injected_obj with async_get_injected_obj when in an async context.
affects: <1.4.2
deprecatedDirect import from fastapi_injectable.util (e.g., from fastapi_injectable.util import get_injected_obj) is considered internal and may change without notice.
fix
Use from fastapi_injectable import get_injected_obj.
affects: all
breakingIn v1.4.5, the internal async exit stack management changed. If you manually managed exit stacks, your code may break.
fix
Let fastapi-injectable handle stack management; avoid overriding internal AsyncExitStack.
affects: >=1.4.5
gotchaDependency overrides set via app.dependency_overrides are NOT automatically respected unless you use get_injected_obj with the updated override mechanism (v1.4.0+).
fix
Use the override parameter of get_injected_obj or ensure app.dependency_overrides is applied before calling.
affects: >=1.4.0
Errors
Common errors & fixes
RuntimeError: You cannot use AsyncToSync in the same thread as an async event loop
Calling get_injected_obj() inside an already running async context.
fix
Use async_get_injected_obj() instead: from fastapi_injectable import async_get_injected_obj; result = await async_get_injected_obj(func)
ImportError: cannot import name 'get_injected_obj' from 'fastapi_injectable.util'
Using the internal module path instead of the public API.
fix
Use: from fastapi_injectable import get_injected_obj
TypeError: 'Depends' object is not callable
Passing Depends() as a parameter without annotating with Annotated.
fix
Use Annotated[type, Depends(dependency)] syntax, e.g., DepDB = Annotated[str, Depends(get_db)]
AttributeError: 'NoneType' object has no attribute 'dependency_overrides'
Passing a FastAPI app that is None to get_injected_obj.
fix
Ensure the app parameter is not None when using overrides, or omit it.
Upgrade
Version history
1.4.7latest on PyPI · released Mar 21, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
fastapi-injectable — pip install fastapi-injectable · libregistry