fastapi-injectable
Use FastAPI's Depends() anywhere — in CLI tools, Celery tasks, background workers, and more. No refactoring needed.
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has no known vulnerabilities, and solves a real problem for FastAPI users who need dependency injection outside routes. Low install friction, permissive license, and production-stable status make it a straightforward choice. The main gotcha is cache management in loops—read the long-running worker documentation before deploying to background tasks.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or higher and FastAPI >=0.112.4,<1.0.0.
- Process-global dependency cache persists across calls in loops; use injectable_scope() or clear_dependency_cache() + cleanup_all_exit_stacks() to reset state per iteration in long-running workers.
- Low friction install with a single runtime dependency (fastapi).
License · maintenance · safety
MIT (permissive) — MIT license (permissive) — you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
last release 2026-06-21 (54 days) · last repo commit 2026-08-01 · 294 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 83,496 downloads/mo, #14,072 on PyPI
Alternatives
Verify before relying
pip install fastapi-injectable
from typing import Annotated
from fastapi import Depends
from fastapi_injectable import injectable
@injectable
def process_data(db: Annotated[Database, Depends(get_db)]) -> str:
return db.query()
result = process_data()- Whether the mypy plugin works correctly with all mypy versions and configurations beyond the documented setup.
- Performance characteristics when dependency graphs are deeply nested or contain many generator-based dependencies.
- Compatibility behavior with FastAPI versions at the upper boundary (0.112.4 through 1.0.0 pre-release).
What it is and what it does
fastapi-injectable is a lightweight decorator and function-based wrapper that extends FastAPI's Depends() system to work outside route handlers. It solves a long-standing limitation (FastAPI issue #1105) where developers had to duplicate dependency logic or introduce a second DI framework when moving from routes into CLI commands, background tasks, Celery jobs, or scheduled workers.
The package provides three main entry points: the @injectable decorator for marking functions, get_injected_obj() for synchronous contexts, and async_get_injected_obj() for code running in an active event loop. It handles full async support, resource cleanup via generator dependencies, optional caching, and graceful shutdown. A bundled mypy plugin enables type-checking of @injectable calls. The single runtime dependency is fastapi itself.
Use it for
- Reuse FastAPI route dependencies in CLI commands without refactoring or duplication.
- Inject dependencies into Celery tasks or background workers using the same Depends() syntax as routes.
- Access FastAPI app.state and registered dependencies in scheduled jobs (cron, APScheduler).
- Write testable functions with dependency overrides using manual mock injection.
- Handle async dependencies in Kafka consumers or streaming callbacks with async_get_injected_obj().
- Manage resource lifecycle (database connections, file handles) via generator-based dependencies in non-route contexts.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has no known vulnerabilities, and solves a real problem for FastAPI users who need dependency injection outside routes. Low install friction, permissive license, and production-stable status make it a straightforward choice. The main gotcha is cache management in loops—read the long-running worker documentation before deploying to background tasks.
Install
fastapi-injectable on PyPI
Before you install
Low friction install with a single runtime dependency (fastapi). Active maintenance: last commit 2026-08-01, 294 repository stars, and production-stable status since 2024-12-18.
Requires Python 3.10 or higher and FastAPI >=0.112.4,<1.0.0. Process-global dependency cache persists across calls in loops; use injectable_scope() or clear_dependency_cache() + cleanup_all_exit_stacks() to reset state per iteration in long-running workers.
License in practice
MIT license (permissive) — you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
pip install fastapi-injectable
from typing import Annotated
from fastapi import Depends
from fastapi_injectable import injectable
@injectable
def process_data(db: Annotated[Database, Depends(get_db)]) -> str:
return db.query()
result = process_data()
Verify before relying
- Whether the mypy plugin works correctly with all mypy versions and configurations beyond the documented setup.
- Performance characteristics when dependency graphs are deeply nested or contain many generator-based dependencies.
- Compatibility behavior with FastAPI versions at the upper boundary (0.112.4 through 1.0.0 pre-release).
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagefastapi |
| Maintenance | Actively maintained 54 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 83,496 / month, #14,072 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: FastAPIIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Free Threading :: 3 - StableTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed |
Evidence: fastapi_injectable-1.6.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “fastapi dependency injection outside routes”
- fastapi-injectableEnables FastAPI's Depends() dependency injection system to work…
- fastapi-injectorIntegrates the injector dependency-injection library with FastAPI,…
- fastapi-sessionsAdds session authentication to FastAPI applications using dependency…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also fast-depends · fastapi-decorators · typer-injector · uncalled-for · taskiq-dependencies · fastapi-injector · FastAPI-SQLAlchemy · taskiq-fastapi · fastapi-health · fastapi-lifespan-manager