skillfed

dependency-injector

Dependency injection framework for Python

dependency-injector v4.49.1 8.4M downloads/30d#1,628 on PyPI4,907
Permissive license Copyright (c) 2024, Roman Mogylatov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:… (full text in the JSON record) Active released

What it is and what it does

Dependency Injector is a framework that centralizes how your application assembles and injects object dependencies. Instead of scattering object creation and wiring throughout your code, you declare all components and their relationships in a container, then use decorators or explicit calls to inject them where needed. This makes testing easier (you can override components with mocks), configuration cleaner (read from yaml, json, ini, environment, or pydantic), and the dependency graph explicit and auditable.

The framework provides multiple provider types—Factory for creating new instances, Singleton for shared instances, Configuration for settings, Resource for lifecycle management (logging, event loops, thread pools), and Callable/Coroutine for wrapping functions. It integrates with Django, Flask, FastAPI, Aiohttp, and other frameworks via a wiring system that automatically injects dependencies into decorated functions and methods. Written in Cython for performance, it supports both synchronous and asynchronous injection and includes mypy-friendly typing stubs.

Use it for:

  • Organize Flask or FastAPI applications by declaring all services (database, cache, API clients) in a container and injecting them into route handlers
  • Replace real API clients with mocks during testing by overriding providers without changing application code
  • Manage configuration across dev, stage, and production environments by reading from different sources and swapping implementations
  • Initialize and manage resources like database connections, thread pools, or event loops with automatic cleanup
  • Build decoupled multi-package applications where each package defines its own container and dependencies

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Dependency Injector is a dependency injection framework that assembles and injects object dependencies into functions and methods, supporting factories, singletons, configuration providers, and async injection.

Yes. Dependency Injector is a mature, actively maintained framework (4907 stars, release 57 days ago, production-stable classifier) with zero known vulnerabilities, permissive licensing, and broad platform support. Install friction is moderate due to Cython compilation but well-mitigated by pre-built wheels. It is worth installing if you want explicit, testable dependency management in a non-trivial application; less essential for simple scripts or if you prefer implicit dependency resolution.

Install

dependency-injector on PyPI

pip

pip install dependency-injector

uv

uv add dependency-injector

poetry

poetry add dependency-injector

Installing dependency-injector

Before you install

Medium install friction due to compiled Cython wheels, but well-supported across platforms (Windows, macOS, Linux, including ARM64 and musl). Active maintenance with release 57 days ago and 4907 GitHub stars indicate stable, production-ready status.

License in practice

BSD 3-Clause permissive license allows commercial use, modification, and distribution with minimal restrictions—standard for open-source frameworks.

Quickstart

pip install dependency-injector

from dependency_injector import containers, providers
from dependency_injector.wiring import Provide, inject

class Container(containers.DeclarativeContainer):
    service = providers.Singleton(MyService)

@inject
def main(service: MyService = Provide[Container.service]) -> None:
    service.do_work()

container = Container()
container.wire(modules=[__name__])
main()

Verify before relying

  • Whether Cython compilation overhead affects startup time in short-lived processes or serverless environments
  • Performance comparison with other DI frameworks in high-throughput scenarios
  • Maturity of async injection support relative to synchronous injection

Package facts

License Copyright (c) 2024, Roman Mogylatov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.8)
Install friction medium — platform-specific wheel
Runtime dependencies 1 — typing-extensions
Maintenance actively maintained — 57 days since the last release
Last repo commit
First released
Downloads 8,389,683/month — #1,628 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: dependency_injector-4.49.1-cp310-abi3-macosx_11_0_arm64.whl; dependency_injector-4.49.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; dependency_injector-4.49.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dependency_injector-4.49.1-cp310-abi3-musllinux_1_2_aarch64.whl; dependency_injector-4.49.1-cp310-abi3-musllinux_1_2_x86_64.whl; dependency_injector-4.49.1-cp310-abi3-win32.whl; dependency_injector-4.49.1-cp310-abi3-win_amd64.whl; dependency_injector-4.49.1-cp38-cp38-macosx_11_0_arm64.whl; dependency_injector-4.49.1-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dependency_injector-4.49.1-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dependency_injector-4.49.1-cp38-cp38-musllinux_1_2_aarch64.whl; dependency_injector-4.49.1-cp38-cp38-musllinux_1_2_x86_64.whl; dependency_injector-4.49.1-cp38-cp38-win32.whl; dependency_injector-4.49.1-cp38-cp38-win_amd64.whl; dependency_injector-4.49.1-cp39-cp39-macosx_11_0_arm64.whl; dependency_injector-4.49.1-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; dependency_injector-4.49.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; dependency_injector-4.49.1-cp39-cp39-musllinux_1_2_aarch64.whl; dependency_injector-4.49.1-cp39-cp39-musllinux_1_2_x86_64.whl; dependency_injector-4.49.1-cp39-cp39-win32.whl

Keywords: Dependency injection, DI, Inversion of Control, IoC, Factory, Singleton, Design patterns, Flask

Development Status :: 5 - Production/StableFramework :: AsyncIOFramework :: BottleFramework :: DjangoFramework :: FlaskFramework :: PylonsFramework :: PyramidFramework :: PytestFramework :: TurboGearsIntended Audience :: DevelopersLicense :: OSI Approved :: BSD 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.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

dependency injection frameworkinversion of control IoCservice containerfactory singleton patternwiring dependencies into functionsconfiguration managementasync dependency injection
dependency-injectioninversion-of-controltesting

More Software Development packages

Further reading