freshcrate
Skin:/
Home > Frameworks > dependency-injector

dependency-injector

Dependency injection framework for Python

Why this rank:Strong adoptionRelease freshnessHealthy release cadence

Description

.. figure:: https://raw.githubusercontent.com/wiki/ets-labs/python-dependency-injector/img/logo.svg :target: https://github.com/ets-labs/python-dependency-injector | .. image:: https://img.shields.io/pypi/v/dependency_injector.svg :target: https://pypi.org/project/dependency-injector/ :alt: Latest Version .. image:: https://img.shields.io/pypi/l/dependency_injector.svg :target: https://pypi.org/project/dependency-injector/ :alt: License .. image:: https://img.shields.io/pypi/pyversions/dependency_injector.svg :target: https://pypi.org/project/dependency-injector/ :alt: Supported Python versions .. image:: https://img.shields.io/pypi/implementation/dependency_injector.svg :target: https://pypi.org/project/dependency-injector/ :alt: Supported Python implementations .. image:: https://pepy.tech/badge/dependency-injector :target: https://pepy.tech/project/dependency-injector :alt: Downloads .. image:: https://pepy.tech/badge/dependency-injector/month :target: https://pepy.tech/project/dependency-injector :alt: Downloads .. image:: https://pepy.tech/badge/dependency-injector/week :target: https://pepy.tech/project/dependency-injector :alt: Downloads .. image:: https://img.shields.io/pypi/wheel/dependency-injector.svg :target: https://pypi.org/project/dependency-injector/ :alt: Wheel .. image:: https://img.shields.io/github/actions/workflow/status/ets-labs/python-dependency-injector/tests-and-linters.yml?branch=master :target: https://github.com/ets-labs/python-dependency-injector/actions :alt: Build Status .. image:: https://coveralls.io/repos/github/ets-labs/python-dependency-injector/badge.svg?branch=master :target: https://coveralls.io/github/ets-labs/python-dependency-injector?branch=master :alt: 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 <https://python-dependency-injector.ets-labs.org/providers/index.html>`_. - **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 <https://python-dependency-injector.ets-labs.org/providers/overriding.html>`_. - **Configuration**. Reads configuration from ``yaml``, ``ini``, and ``json`` files, ``pydantic`` settings, environment variables, and dictionaries. See `Configuration provider <https://python-dependency-injector.ets-labs.org/providers/configuration.html>`_. - **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 <https://python-dependency-injector.ets-labs.org/providers/resource.html>`_. - **Containers**. Provides declarative and dynamic containers. See `Containers <https://python-dependency-injector.ets-labs.org/containers/index.html>`_. - **Wiring**. Injects dependencies into functions and methods. Helps integrate with other frameworks: Django, Flask, Aiohttp, Sanic, FastAPI, etc. See `Wiring <https://python-dependency-injector.ets-labs.org/wiring.html>`_. - **Asynchronous**. Supports asynchronous injections. See `Asynchronous injections <https://python-dependency-injector.ets-labs.org/providers/async.html>`_. - **Typing**. Provides typing stubs, ``mypy``-friendly. See `Typing and mypy <https://python-dependency-injector.ets-labs.org/providers/typing_mypy.html>`_. - **Performance**. Fast. Written in ``Cython``. - **Maturity**. Mature and production-ready. Well-tested, documented, and supported. .. code-block:: python 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()

Release History

VersionChangesUrgencyDate
4.49.0Imported from PyPI (4.49.0)Low4/21/2026
4.48.3## What's Changed * Fix providers.Resource missing overloads for AbstractContextManager and AbstractAsyncContextManager by @leonarduschen in https://github.com/ets-labs/python-dependency-injector/pull/927 * Fast depends v3 compatibility fix by @AndrianEquestrian in https://github.com/ets-labs/python-dependency-injector/pull/933 * Allow explicit typing on selector using TypeVar with default Any by @leonarduschen in https://github.com/ets-labs/python-dependency-injector/pull/932 * Retrofit assLow12/4/2025
4.48.2## What's Changed * Fix grammar in Declarative Container documentation by @okotdaniel in https://github.com/ets-labs/python-dependency-injector/pull/916 * Add warnings for unresolved markers by @ZipFile in https://github.com/ets-labs/python-dependency-injector/commit/1222827a5e76b1051de850aa34da12118908ffbd * Build ABI3 wheels only for Python>=3.10 by @ZipFile in https://github.com/ets-labs/python-dependency-injector/commit/891f8b4190dbb883a68e5b9083e6b96acc555dad ## New Contributors * @oLow9/19/2025
4.48.1## What's Changed * Improve performance of ``dependency_injector._cwiring.DependencyResolver`` by @ZipFile in https://github.com/ets-labs/python-dependency-injector/commit/eb74b1e9d0b681008de531a697c7caeaafbd1e30 * Add ``typing-extensions`` as a dependency for older Python versions (<3.11) by @ZipFile in https://github.com/ets-labs/python-dependency-injector/commit/be7d25518de833ef02f97567b8def9f5d1b80ab1 * Produce warning on ``@inject``s without ``Provide[...]`` marks by @ZipFile in https:Low9/19/2025
4.48.0## What's Changed * Use cache in _fetch_reference_injections() by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/897 * Add Context Manager support to Resource provider by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/899 * Add support for async generator injections by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/900 * Add support for Fast Depends by @AndrianEquestrian in https://github.com/ets-labs/python-dependencLow6/16/2025
4.47.1## What's Changed * Fix wiring marker typing by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/896 * Strip debug symbols in wheels **Full Changelog**: https://github.com/ets-labs/python-dependency-injector/compare/4.47.0...4.47.1Low6/16/2025
4.47.0## What's Changed * Fix infinite loop with Closing+ConfigurationOption by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/871 * Remove unused `root` property from ConfigurationOption by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/875 * Fix incorrect monkeypatching during `wire()` that could violate MRO in some classes by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/886 * Add support for `Annotated` type for moduLow5/29/2025
4.42.0## What's Changed * Add a link to my Github Sponsors profile by @rmk135 in https://github.com/ets-labs/python-dependency-injector/pull/806 * Add Python 3.12 Support (#752) by @rmk135 in https://github.com/ets-labs/python-dependency-injector/pull/765 **Full Changelog**: https://github.com/ets-labs/python-dependency-injector/compare/4.41.0...4.42.0Low2/27/2025
4.43.0## What's Changed * Migrate to Cython3 by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/813 * Add support for Python 3.13 by @rmk135 in https://github.com/ets-labs/python-dependency-injector/pull/828 **Full Changelog**: https://github.com/ets-labs/python-dependency-injector/compare/4.42.0...4.43.0Low2/27/2025
4.44.0## What's Changed * PEP-517 by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/829 * Pydantic 2 support by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/832 * Fix sdist build for publishing by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/836 **Full Changelog**: https://github.com/ets-labs/python-dependency-injector/compare/4.43.0...4.44.0Low2/27/2025
4.45.0## What's Changed * Upgrade testing deps by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/837 * Update examples by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/838 * Fix grammar in docs by @dijonkitchen in https://github.com/ets-labs/python-dependency-injector/pull/709 * Remove `six` by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/840 * Improve debugability of `deepcopy` errors by @ZipFile in https://github.com/Low2/27/2025
4.46.0## What's Changed * Migrate CI pipeline to `actions/upload-artifact@v4` by @ZipFile in https://github.com/ets-labs/python-dependency-injector/pull/847 * Fix type propogation through Provider by @philipbjorge in https://github.com/ets-labs/python-dependency-injector/pull/744 https://github.com/ets-labs/python-dependency-injector/pull/733 * Add test fixture and update documentation for movie-lister example by @mrKazzila in https://github.com/ets-labs/python-dependency-injector/pull/747 * Use nLow2/27/2025

Dependencies & License Audit

Loading dependencies...

Similar Packages

pdmA modern Python package and dependency manager supporting the latest PEP standards2.27.0
factory-boyA versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby.3.3.3
schemathesisProperty-based testing framework for Open API and GraphQL based appsv4.21.1
ctranslate2Fast inference engine for Transformer modelsv4.8.0
cadwynProduction-ready community-driven modern Stripe-like API versioning in FastAPI7.0.0

More from pypi

markitdownUtility tool for converting various files to Markdown
fastapiFastAPI framework, high performance, easy to learn, fast to code, ready for production
djangoA high-level Python web framework that encourages rapid development and clean, pragmatic design.
flaskA simple framework for building complex web applications.

More in Frameworks

spec_driven_developSpec-Driven Develop is a platform-agnostic AI agent skill that automates the pre-development workflow for large-scale complex tasks. It is not a framework, not a runtime, not a package manager — it is
DrasilGenerate all the things (focusing on research software)
langchainThe agent engineering platform
deer-flowAn open-source long-horizon SuperAgent harness that researches, codes, and creates. With the help of sandboxes, memories, tools, skill, subagents and message gateway, it handles different levels of ta