skillfed

inject

Python dependency injection framework.

inject v5.5.0 2.3M downloads/30d#3,141 on PyPI774
Permissive license Apache-2.0 Active released

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 inject

uv

uv add inject

poetry

poetry add inject

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Libraries :: Python Modules

Tags

dependency injection pythonautoparams type annotationsinversion of control frameworkinject decoratorservice locator patternbind dependencies pythonthread-safe di container
dependency-injectioninversion-of-controltesting

More Python Modules packages