inject
Python dependency injection framework.
What it is and what it does
Inject is a dependency injection framework that decouples object creation from usage by automatically wiring dependencies into functions and classes. It uses type annotations or explicit binding declarations to resolve and inject dependencies at runtime. The framework does not intercept or modify class constructors, instead offering decorators like @autoparams and @params, instance attributes via inject.attr, and direct instance retrieval via inject.instance.
The package supports multiple binding strategies: instance bindings (always return the same object), constructor bindings (create singletons on first injection), and provider bindings (call a function on each injection). It integrates transparently with tests through configuration clearing, handles context managers, and is thread-safe after initial configuration. Runtime binding can be disabled to catch unbound dependencies early.
Use it for:
- Decouple service implementations from their consumers in web frameworks or CLI applications by binding interfaces to concrete implementations.
- Simplify test setup by configuring mock dependencies without modifying production code or class constructors.
- Manage shared resources like database connections or caches across an application by binding them once and injecting where needed.
- Build modular applications where different environments (dev, test, production) use different implementations of the same interface.
- Reduce boilerplate in class hierarchies by using inject.attr to declare dependencies as class properties instead of constructor parameters.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a lightweight dependency injection framework for Python that automatically injects dependencies into functions and classes using type annotations or explicit binding declarations.
Yes. Inject is a mature, actively maintained dependency injection framework with no external dependencies, permissive licensing, and no known vulnerabilities. It is well-suited for Python projects that need lightweight, non-invasive dependency management. Install it if you want a simple alternative to heavier frameworks; skip it if your project already uses a framework with built-in DI (Django, FastAPI) or if you prefer explicit parameter passing.
Install
inject on PyPI
pip
pip install injectuv
uv add injectpoetry
poetry add injectInstalling inject
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release 32 days ago; repo shows 774 stars and last commit on 2026-07-27. Requires Python 3.10+.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install inject
import inject
@inject.autoparams
def my_function(cache: RedisCache):
pass
def config(binder):
binder.bind(RedisCache, RedisCache('localhost:1234'))
inject.configure(config)
my_function() # cache is automatically injected
Requires Python 3.10 or later; type annotations are required for autoparams decorator to work.
Verify before relying
- Whether the package's thread-safety guarantees hold under all concurrent binding scenarios
- Performance characteristics when managing large dependency graphs or high-frequency injection calls
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 32 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,322,011/month — #3,141 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: inject-5.5.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
in-n-outLightweight dependency injection framework…
permissive · top 15,000 on PyPI
injectorInjector is a Python dependency injection…
permissive · top 5,000 on PyPI
dependency-injectorDependency Injector is a dependency injection…
permissive · top 5,000 on PyPI
conda-injectInjects a conda environment's packages into the…
unclear · top 15,000 on PyPI
pinjectPinject is a dependency injection library that…
permissive · top 15,000 on PyPI
Flask-InjectorIntegrates dependency injection into Flask…
permissive · top 15,000 on PyPI
simple-diA strictly typed dependency injection library…
permissive · top 15,000 on PyPI
kinkKink is a lightweight dependency injection…
permissive · top 15,000 on PyPI
allukaAlluka is a type-based dependency injection…
permissive · top 15,000 on PyPI
fastapi-injectorIntegrates the injector dependency-injection…
permissive · top 15,000 on PyPI