# dependency-injector

> Dependency injection framework for Python

- **URL**: https://www.freshcrate.ai/projects/dependency-injector
- **Author**: pypi
- **Category**: Frameworks
- **Latest version**: `4.49.0` (2026-04-21)
- **License**: non-standard
- **Source**: https://github.com/ets-labs/python-dependency-injector
- **Homepage**: https://pypi.org/project/dependency-injector/
- **Language**: Python
- **GitHub**: 4,847 stars, 342 forks
- **Registry**: pypi (`dependency-injector`)
- **Tags**: `control`, `dependency`, `di`, `factory`, `injection`, `inversion`, `ioc`, `of`, `pypi`

## 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()

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `4.49.0` | 2026-04-21 | Low | Imported from PyPI (4.49.0) |
| `4.48.3` | 2025-12-04 | Low | ## 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 ass |
| `4.48.2` | 2025-09-19 | Low | ## 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 * @o |
| `4.48.1` | 2025-09-19 | Low | ## 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: |
| `4.48.0` | 2025-06-16 | Low | ## 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-dependenc |
| `4.47.1` | 2025-06-16 | Low | ## 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.1 |
| `4.47.0` | 2025-05-29 | Low | ## 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 modu |
| `4.42.0` | 2025-02-27 | Low | ## 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.0 |
| `4.43.0` | 2025-02-27 | Low | ## 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.0 |
| `4.44.0` | 2025-02-27 | Low | ## 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.0 |

## Citation

- HTML: https://www.freshcrate.ai/projects/dependency-injector
- Markdown: https://www.freshcrate.ai/projects/dependency-injector.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/dependency-injector/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
