dependency-injector 4.48.2


pip install dependency-injector

  Latest version

Released: Sep 19, 2025


Meta
Author: Roman Mogylatov
Maintainer: Roman Mogylatov
Requires Python: >=3.8

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: BSD License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Framework
  • AsyncIO
  • Bottle
  • Django
  • Flask
  • Pylons
  • Pyramid
  • Pytest
  • TurboGears

Topic
  • Software Development
  • Software Development :: Libraries
  • Software Development :: Libraries :: Python Modules
https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/logo.svg

Latest Version License Supported Python versions Supported Python implementations Downloads Downloads Downloads Wheel Build Status Coverage Status

What is Dependency Injector?

Dependency Injector is a dependency injection framework for Python.

It helps implement the dependency injection principle.

Key features of the Dependency Injector:

  • Providers. Provides Factory, Singleton, Callable, Coroutine, Object, List, Dict, Configuration, Resource, Dependency, and Selector providers that help assemble your objects. See Providers.

  • Overriding. Can override any provider by another provider on the fly. This helps in testing and configuring dev/stage environment to replace API clients with stubs etc. See Provider overriding.

  • Configuration. Reads configuration from yaml, ini, and json files, pydantic settings, environment variables, and dictionaries. See Configuration provider.

  • Resources. Helps with initialization and configuring of logging, event loop, thread or process pool, etc. Can be used for per-function execution scope in tandem with wiring. See Resource provider.

  • Containers. Provides declarative and dynamic containers. See Containers.

  • Wiring. Injects dependencies into functions and methods. Helps integrate with other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc. See Wiring.

  • Asynchronous. Supports asynchronous injections. See Asynchronous injections.

  • Typing. Provides typing stubs, mypy-friendly. See Typing and mypy.

  • Performance. Fast. Written in Cython.

  • Maturity. Mature and production-ready. Well-tested, documented, and supported.

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


class Container(containers.DeclarativeContainer):

    config = providers.Configuration()

    api_client = providers.Singleton(
        ApiClient,
        api_key=config.api_key,
        timeout=config.timeout,
    )

    service = providers.Factory(
        Service,
        api_client=api_client,
    )


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


if __name__ == "__main__":
    container = Container()
    container.config.api_key.from_env("API_KEY", required=True)
    container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
    container.wire(modules=[__name__])

    main()  # <-- dependency is injected automatically

    with container.api_client.override(mock.Mock()):
        main()  # <-- overridden dependency is injected automatically

When you call the main() function the Service dependency is assembled and injected automatically.

When you do testing, you call the container.api_client.override() method to replace the real API client with a mock. When you call main(), the mock is injected.

You can override any provider with another provider.

It also helps you in a re-configuring project for different environments: replace an API client with a stub on the dev or stage.

With the Dependency Injector, object assembling is consolidated in a container. Dependency injections are defined explicitly. This makes it easier to understand and change how an application works.

https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/di-readme.svg

Visit the docs to know more about the Dependency injection and inversion of control in Python.

Installation

The package is available on the PyPi:

pip install dependency-injector

Documentation

The documentation is available here.

Examples

Choose one of the following:

Tutorials

Choose one of the following:

Concept

The framework stands on the PEP20 (The Zen of Python) principle:

Explicit is better than implicit

You need to specify how to assemble and where to inject the dependencies explicitly.

The power of the framework is in its simplicity. Dependency Injector is a simple tool for the powerful concept.

Frequently asked questions

What is dependency injection?
  • dependency injection is a principle that decreases coupling and increases cohesion

Why should I do the dependency injection?
  • your code becomes more flexible, testable, and clear ๐Ÿ˜Ž

How do I start applying the dependency injection?
  • you start writing the code following the dependency injection principle

  • you register all of your application components and their dependencies in the container

  • when you need a component, you specify where to inject it or get it from the container

What price do I pay and what do I get?
  • you need to explicitly specify the dependencies

  • it will be extra work in the beginning

  • it will payoff as project grows

Have a question?
Found a bug?
Want to help?
  • โญ๏ธ Star the Dependency Injector on the Github

  • ๐Ÿ†• Start a new project with the Dependency Injector

  • ๐Ÿ’ฌ Tell your friend about the Dependency Injector

Want to contribute?
  • ๐Ÿ”€ Fork the project

  • โฌ…๏ธ Open a pull request to the develop branch

4.48.2 Sep 19, 2025
4.48.1 Jun 20, 2025
4.48.0 Jun 16, 2025
4.47.1 May 30, 2025
4.47.0 May 28, 2025
4.47.0a3 May 27, 2025
4.46.0 Feb 25, 2025
4.45.0 Jan 06, 2025
4.44.0 Dec 07, 2024
4.43.0 Nov 04, 2024
4.42.0 Sep 10, 2024
4.42.0b1 Aug 08, 2024
4.41.0 Dec 19, 2022
4.40.0 Aug 04, 2022
4.39.1 Mar 30, 2022
4.39.0 Mar 28, 2022
4.38.0 Jan 31, 2022
4.37.0 Nov 01, 2021
4.36.2 Sep 28, 2021
4.36.0 Aug 25, 2021
4.35.2 Aug 06, 2021
4.35.1 Aug 05, 2021
4.35.0 Jul 29, 2021
4.34.2 Jul 24, 2021
4.34.1 Jul 20, 2021
4.34.0 Jun 24, 2021
4.33.0 Jun 14, 2021
4.32.3 May 20, 2021
4.32.2 Apr 27, 2021
4.32.1 Apr 25, 2021
4.32.0 Apr 19, 2021
4.31.2 Mar 30, 2021
4.31.1 Mar 24, 2021
4.31.0 Mar 21, 2021
4.30.0 Mar 20, 2021
4.29.2 Mar 08, 2021
4.29.1 Mar 06, 2021
4.29.0 Mar 03, 2021
4.28.1 Mar 01, 2021
4.28.0 Mar 01, 2021
4.27.0 Feb 27, 2021
4.26.0 Feb 21, 2021
4.25.1 Feb 19, 2021
4.25.0 Feb 18, 2021
4.24.0 Feb 18, 2021
4.23.5 Feb 17, 2021
4.23.4 Feb 17, 2021
4.23.3 Feb 17, 2021
4.23.2 Feb 16, 2021
4.23.1 Feb 15, 2021
4.23.0 Feb 15, 2021
4.22.1 Feb 15, 2021
4.22.0 Feb 15, 2021
4.21.0 Feb 13, 2021
4.20.2 Feb 09, 2021
4.20.1 Feb 07, 2021
4.20.0 Feb 07, 2021
4.19.0 Feb 06, 2021
4.18.0 Feb 05, 2021
4.17.0 Feb 04, 2021
4.16.0 Feb 03, 2021
4.15.0 Feb 03, 2021
4.14.0 Feb 01, 2021
4.13.2 Jan 29, 2021
4.13.1 Jan 29, 2021
4.13.0 Jan 29, 2021
4.12.0 Jan 29, 2021
4.11.3 Jan 28, 2021
4.11.2 Jan 27, 2021
4.11.1 Jan 27, 2021
4.11.0 Jan 27, 2021
4.10.3 Jan 20, 2021
4.10.2 Jan 19, 2021
4.10.1 Jan 19, 2021
4.10.0 Jan 16, 2021
4.9.1 Jan 15, 2021
4.9.0 Jan 15, 2021
4.8.3 Jan 15, 2021
4.8.2 Jan 13, 2021
4.8.1 Jan 12, 2021
4.8.0 Jan 12, 2021
4.7.0 Jan 11, 2021
4.6.1 Jan 11, 2021
4.6.0 Jan 11, 2021
4.5.4 Dec 10, 2020
4.5.3 Dec 06, 2020
4.5.2 Dec 05, 2020
4.5.1 Nov 20, 2020
4.5.0 Nov 20, 2020
4.4.1 Nov 18, 2020
4.4.0 Nov 15, 2020
4.3.9 Nov 13, 2020
4.3.8 Nov 12, 2020
4.3.7 Nov 10, 2020
4.3.6 Nov 05, 2020
4.3.5 Nov 05, 2020
4.3.4 Nov 05, 2020
4.3.3 Nov 03, 2020
4.3.2 Oct 30, 2020
4.3.1 Oct 30, 2020
4.3.0 Oct 30, 2020
4.2.0 Oct 29, 2020
4.1.8 Oct 29, 2020
4.1.7 Oct 29, 2020
4.1.6 Oct 28, 2020
4.1.5 Oct 27, 2020
4.1.4 Oct 27, 2020
4.1.2 Oct 27, 2020
4.1.1 Oct 27, 2020
4.1.0 Oct 25, 2020
4.0.6 Oct 20, 2020
4.0.5 Oct 19, 2020
4.0.4 Oct 19, 2020
4.0.3 Oct 17, 2020
4.0.2 Oct 16, 2020
4.0.1 Oct 16, 2020
4.0.0 Oct 09, 2020
4.0.0a2 Sep 28, 2020
4.0.0a1 Sep 21, 2020
3.44.0 Sep 14, 2020
3.43.1 Sep 10, 2020
3.43.0 Sep 10, 2020
3.42.0 Sep 09, 2020
3.41.0 Sep 08, 2020
3.40.0 Sep 07, 2020
3.39.0 Sep 05, 2020
3.38.1 Sep 04, 2020
3.38.0 Sep 04, 2020
3.37.0 Sep 03, 2020
3.36.0 Sep 03, 2020
3.35.1 Sep 02, 2020
3.35.0 Sep 02, 2020
3.34.0 Sep 01, 2020
3.33.0 Aug 27, 2020
3.32.3 Aug 26, 2020
3.32.2 Aug 26, 2020
3.32.1 Aug 25, 2020
3.32.0 Aug 24, 2020
3.31.0 Aug 21, 2020
3.30.4 Aug 16, 2020
3.30.3 Aug 16, 2020
3.30.2 Aug 14, 2020
3.30.1 Aug 14, 2020
3.30.0 Aug 12, 2020
3.29.0 Aug 11, 2020
3.28.1 Aug 10, 2020
3.28.0 Aug 08, 2020
3.27.0 Aug 06, 2020
3.26.0 Aug 03, 2020
3.25.1 Jul 30, 2020
3.25.0 Jul 30, 2020
3.24.1 Jul 29, 2020
3.24.0 Jul 29, 2020
3.23.2 Jul 24, 2020
3.23.1 Jul 22, 2020
3.23.0 Jul 20, 2020
3.22.0 Jul 18, 2020
3.21.2 Jul 14, 2020
3.21.1 Jul 14, 2020
3.21.0 Jul 14, 2020
3.20.1 Jul 11, 2020
3.20.0 Jul 11, 2020
3.19.2 Jul 03, 2020
3.19.1 Jul 02, 2020
3.19.0 Jun 29, 2020
3.18.1 Jun 26, 2020
3.18.0 Jun 25, 2020
3.17.1 Jun 23, 2020
3.17.0 Jun 23, 2020
3.16.1 Jun 17, 2020
3.16.0 Jun 14, 2020
3.15.6 Feb 18, 2020
3.15.5 Feb 18, 2020
3.15.4 Jan 27, 2020
3.15.3 Jan 27, 2020
3.15.2 Jan 27, 2020
3.15.1 Jan 27, 2020
3.15.0 Jan 26, 2020
3.14.12 Oct 09, 2019
3.14.11 Oct 08, 2019
3.14.10 Aug 18, 2019
3.14.9 Aug 18, 2019
3.14.8 Jul 29, 2019
3.14.7 Jun 07, 2019
3.14.6 May 09, 2019
3.14.5 Mar 22, 2019
3.14.4 Jan 06, 2019
3.14.3 Dec 22, 2018
3.14.2 Nov 08, 2018
3.14.1 Nov 08, 2018
3.14.0 Oct 19, 2018
3.13.2 Sep 02, 2018
3.13.1 Aug 16, 2018
3.13.0 Aug 16, 2018
3.12.4 Jul 26, 2018
3.12.3 Jul 24, 2018
3.12.2 Jul 03, 2018
3.12.1 Jul 02, 2018
3.12.0 Apr 23, 2018
3.11.3 Feb 22, 2018
3.11.2 Feb 22, 2018
3.11.1 Jan 26, 2018
3.11.0 Jan 24, 2018
3.10.0 Jan 21, 2018
3.9.1 Dec 25, 2017
3.9.0 Dec 25, 2017
3.8.2 Nov 30, 2017
3.8.1 Nov 30, 2017
3.8.0 Nov 21, 2017
3.7.1 Oct 30, 2017
3.7.0 Oct 13, 2017
3.6.1 Aug 08, 2017
3.6.0 Jul 09, 2017
3.5.0 Jul 07, 2017
3.4.8 Jun 08, 2017
3.4.7 May 29, 2017
3.4.6 May 29, 2017
3.4.5 May 17, 2017
3.4.4 May 08, 2017
3.4.3 Apr 18, 2017
3.4.2 Apr 18, 2017
3.4.1 Apr 07, 2017
3.4.0 Apr 06, 2017
3.3.7 Mar 28, 2017
3.3.6 Mar 28, 2017
3.3.5 Mar 26, 2017
3.3.4 Mar 25, 2017
3.3.3 Mar 15, 2017
3.3.2 Feb 28, 2017
3.3.1 Feb 01, 2017
3.3.0 Jan 29, 2017
3.2.5 Jan 29, 2017
3.2.4 Jan 10, 2017
3.2.3 Dec 27, 2016
3.2.2 Dec 04, 2016
3.2.1 Dec 02, 2016
3.2.0 Dec 02, 2016
3.1.5 Nov 23, 2016
3.1.4 Nov 17, 2016
3.1.3 Nov 15, 2016
3.1.2 Nov 15, 2016
3.1.1 Nov 13, 2016
3.1.0 Nov 11, 2016
3.0.1 Nov 11, 2016
3.0.0 Nov 11, 2016
2.2.10 Oct 20, 2016
2.2.9 Oct 19, 2016
2.2.8 Oct 13, 2016
2.2.7 Oct 12, 2016
2.2.6 Oct 12, 2016
2.2.5 Oct 11, 2016
2.2.4 Oct 11, 2016
2.2.3 Oct 07, 2016
2.2.2 Oct 07, 2016
2.2.1 Oct 07, 2016
2.2.0 Sep 22, 2016
2.1.1 Sep 07, 2016
2.1.0 Aug 18, 2016
2.0.0 Jun 09, 2016

Wheel compatibility matrix

Platform CPython 3.8 CPython 3.9 CPython >=3.10 (abi3) PyPy 3.10 (pp73) PyPy 3.11 (pp73)
macosx_11_0_arm64
manylinux1_x86_64
manylinux2014_aarch64
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_x86_64
manylinux_2_28_aarch64
manylinux_2_28_x86_64
manylinux_2_5_x86_64
musllinux_1_2_aarch64
musllinux_1_2_x86_64
win32
win_amd64

Files in release

dependency_injector-4.48.2-cp310-abi3-macosx_11_0_arm64.whl (1.7MiB)
dependency_injector-4.48.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.8MiB)
dependency_injector-4.48.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.7MiB)
dependency_injector-4.48.2-cp310-abi3-musllinux_1_2_aarch64.whl (1.7MiB)
dependency_injector-4.48.2-cp310-abi3-musllinux_1_2_x86_64.whl (1.8MiB)
dependency_injector-4.48.2-cp310-abi3-win32.whl (1.4MiB)
dependency_injector-4.48.2-cp310-abi3-win_amd64.whl (1.6MiB)
dependency_injector-4.48.2-cp38-cp38-macosx_11_0_arm64.whl (1.7MiB)
dependency_injector-4.48.2-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.8MiB)
dependency_injector-4.48.2-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8MiB)
dependency_injector-4.48.2-cp38-cp38-musllinux_1_2_aarch64.whl (1.8MiB)
dependency_injector-4.48.2-cp38-cp38-musllinux_1_2_x86_64.whl (1.8MiB)
dependency_injector-4.48.2-cp38-cp38-win32.whl (1.5MiB)
dependency_injector-4.48.2-cp38-cp38-win_amd64.whl (1.7MiB)
dependency_injector-4.48.2-cp39-cp39-macosx_11_0_arm64.whl (1.8MiB)
dependency_injector-4.48.2-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.8MiB)
dependency_injector-4.48.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9MiB)
dependency_injector-4.48.2-cp39-cp39-musllinux_1_2_aarch64.whl (1.8MiB)
dependency_injector-4.48.2-cp39-cp39-musllinux_1_2_x86_64.whl (1.9MiB)
dependency_injector-4.48.2-cp39-cp39-win32.whl (1.5MiB)
dependency_injector-4.48.2-cp39-cp39-win_amd64.whl (1.7MiB)
dependency_injector-4.48.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl (1.7MiB)
dependency_injector-4.48.2-pp310-pypy310_pp73-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.7MiB)
dependency_injector-4.48.2-pp310-pypy310_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.7MiB)
dependency_injector-4.48.2-pp310-pypy310_pp73-win_amd64.whl (1.5MiB)
dependency_injector-4.48.2-pp311-pypy311_pp73-macosx_11_0_arm64.whl (1.7MiB)
dependency_injector-4.48.2-pp311-pypy311_pp73-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.7MiB)
dependency_injector-4.48.2-pp311-pypy311_pp73-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.7MiB)
dependency_injector-4.48.2-pp311-pypy311_pp73-win_amd64.whl (1.5MiB)
dependency_injector-4.48.2.tar.gz (1.1MiB)
Extras:
Dependencies:
typing-extensions