# ets-labs/python-dependency-injector

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/ets-labs-python-dependency-injector).**

4,805 stars · 344 forks · Python · bsd-3-clause

## Links

- GitHub: https://github.com/ets-labs/python-dependency-injector
- Homepage: https://python-dependency-injector.ets-labs.org/
- awesome-repositories: https://awesome-repositories.com/repository/ets-labs-python-dependency-injector.md

## Topics

`aiohttp` `asyncio` `dependency-injection` `dependency-injection-container` `dependency-injection-framework` `design-patterns` `factory` `flask` `flask-application` `flask-restful` `ioc` `ioc-container` `python` `python-2` `python-3` `python3` `singleton` `threadlocal`

## Description

This is a dependency injection framework and inversion of control container for Python. It decouples object creation from business logic by managing how services and their dependencies are assembled, delivered, and linked within an application.

The framework is distinguished by its ability to perform automated component wiring, using import hooks and decorators to inject dependencies into functions and classes across different modules. It supports non-blocking flows through an asynchronous dependency resolver and manages the initialization and shutdown sequences of shared external resources as a resource lifecycle manager.

It provides a comprehensive suite of provider types, including singletons, factories, and placeholders, to control object lifetimes and assembly. The system includes capabilities for application configuration management via YAML, JSON, and environment variables, as well as tools for software test isolation through runtime dependency overriding.

Integration utilities are available for bridging managed dependencies into web frameworks, ASGI lifecycles, and event handlers.

## Tags

### Part of an Awesome List

- [Dependency Injection](https://awesome-repositories.com/f/awesome-lists/devtools/dependency-injection.md) — Provides a comprehensive framework for managing object lifecycles and decoupling components through dependency injection.
- [Declarative Registries](https://awesome-repositories.com/f/awesome-lists/data/container-registries/declarative-registries.md) — Organizes dependency providers as class attributes to decouple object creation from business logic.

### Software Engineering & Architecture

- [Automated Dependency Wiring](https://awesome-repositories.com/f/software-engineering-architecture/automated-dependency-wiring.md) — Installs a module loader hook to automatically resolve and wire dependencies when modules are imported into the application. ([source](https://python-dependency-injector.ets-labs.org/api/wiring.html))
- [Automated Component Wiring](https://awesome-repositories.com/f/software-engineering-architecture/automated-component-wiring.md) — Injects dependencies into functions and classes across modules without manually passing objects through every layer.
- [Dependency Injection Containers](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers.md) — Defines the assembly of services and their dependencies in a central container to decouple object creation from usage. ([source](https://python-dependency-injector.ets-labs.org/examples/aiohttp.html))
- [Callable Wiring](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/callable-wiring.md) — Binds container providers to functions or methods across different modules and packages using decorators. ([source](https://python-dependency-injector.ets-labs.org/api/wiring.html))
- [Component Wiring](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/component-wiring.md) — Aggregates multiple package containers into a single application container to resolve dependencies and connect decoupled modules. ([source](https://python-dependency-injector.ets-labs.org/examples/decoupled-packages.html))
- [Structured Provider Containers](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/structured-provider-containers.md) — Organizes providers as class attributes to create a structured, reusable assembly of dependencies. ([source](https://python-dependency-injector.ets-labs.org/containers/declarative.html))
- [Dependency Injection Frameworks](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-frameworks.md) — Implements inversion of control to manage component dependencies and object lifecycles in Python.
- [Automatic Constructor Injection](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/automatic-constructor-injection.md) — Supplies required objects to functions or classes at runtime using markers to eliminate manual instantiation. ([source](https://python-dependency-injector.ets-labs.org/introduction/di_in_python.html))
- [Dynamic Dependency Overriding](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/dynamic-dependency-overriding.md) — Replaces a provider with another implementation at runtime to facilitate testing with stubs. ([source](https://python-dependency-injector.ets-labs.org/))
- [Factory-Based Instantiation](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/factory-based-instantiation.md) — Creates new object instances by injecting defined dependencies or assigning attributes during initialization. ([source](https://python-dependency-injector.ets-labs.org/providers/factory.html))
- [Object Assembly Management](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/object-assembly-management.md) — Manages the assembly and linking of objects using diverse provider types to handle complex dependency graphs. ([source](https://python-dependency-injector.ets-labs.org/_sources/index.rst.txt))
- [Object Lifecycle Management](https://awesome-repositories.com/f/software-engineering-architecture/dynamic-object-instantiation/object-lifecycle-management.md) — Manages object instantiation through specific provider types like singletons, factories, and asynchronous coroutines.
- [External Resource Initialization](https://awesome-repositories.com/f/software-engineering-architecture/external-resource-initialization.md) — Manages the setup and teardown of shared external resources, such as connection pools, and injects them into dependent services. ([source](https://python-dependency-injector.ets-labs.org/examples/boto3.html))
- [Asynchronous Providers](https://awesome-repositories.com/f/software-engineering-architecture/integration-extensibility/dependency-injection/asynchronous-providers.md) — Resolves dependencies asynchronously using await expressions to handle non-blocking object initialization. ([source](https://python-dependency-injector.ets-labs.org/api/providers.html))
- [Inversion-of-Control Containers](https://awesome-repositories.com/f/software-engineering-architecture/inversion-of-control-containers.md) — Provides a central registry for defining object instantiation and linkage to manage complex dependency graphs.
- [Object Lifetime Management](https://awesome-repositories.com/f/software-engineering-architecture/object-lifetime-management.md) — Controls whether a dependency is created as a new instance every time or as a single shared instance. ([source](https://python-dependency-injector.ets-labs.org/tutorials/cli.html))
- [Resource Lifecycle Managers](https://awesome-repositories.com/f/software-engineering-architecture/rpc-cancellation/asynchronous-operation-cancellation/context-aware-cancellation/resource-lifecycle-managers.md) — Handles the initialization and shutdown of shared components using functions, context managers, or asynchronous initializers. ([source](https://python-dependency-injector.ets-labs.org/_sources/index.rst.txt))
- [Shared Resource Lifecycles](https://awesome-repositories.com/f/software-engineering-architecture/rpc-cancellation/asynchronous-operation-cancellation/context-aware-cancellation/resource-lifecycle-managers/shared-resource-lifecycles.md) — Coordinates the initialization and shutdown sequences of shared external resources and singletons.
- [Service Instance Managers](https://awesome-repositories.com/f/software-engineering-architecture/service-instance-managers.md) — Implements singleton management to ensure a single instance of a dependency is returned on all requests. ([source](https://python-dependency-injector.ets-labs.org/providers/singleton.html))
- [Application Configuration](https://awesome-repositories.com/f/software-engineering-architecture/application-lifecycle-management/configuration-management/configuration-scopes/application-configuration.md) — Loads and injects settings from environment variables, YAML, JSON, or INI files into application components.
- [Callable-Based Resolution](https://awesome-repositories.com/f/software-engineering-architecture/callable-factories/callable-based-resolution.md) — Resolves and provides objects by calling a function or class with specified positional and keyword arguments. ([source](https://python-dependency-injector.ets-labs.org/api/providers.html))
- [Module-Level Injection](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/module-level-injection.md) — Wires specific modules to a container to inject dependencies directly into functions or endpoints. ([source](https://python-dependency-injector.ets-labs.org/examples/fastapi-sqlalchemy.html))
- [Resolution Verification](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/resolution-verification.md) — Checks if all dependencies in a container are defined or have defaults and raises an error if unresolved. ([source](https://python-dependency-injector.ets-labs.org/containers/check_dependencies.html))
- [Schema-Based Container Initialization](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-containers/schema-based-container-initialization.md) — Builds dependency providers automatically using definitions provided in JSON or YAML schema files. ([source](https://python-dependency-injector.ets-labs.org/api/containers.html))
- [Abstract Dependency Definitions](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/abstract-dependency-definitions.md) — Creates placeholder factories for base classes that must be overridden with concrete implementations. ([source](https://python-dependency-injector.ets-labs.org/providers/factory.html))
- [Dependency Placeholders](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/dependency-placeholders.md) — Creates placeholders for required objects to ensure provided instances match a specified type. ([source](https://python-dependency-injector.ets-labs.org/providers/dependency.html))
- [Provider Definition Inheritance](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/provider-definition-inheritance.md) — Enables extending existing containers to inherit and reuse dependency definitions while specializing new providers. ([source](https://python-dependency-injector.ets-labs.org/containers/declarative.html))
- [Provider Delegation](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/provider-delegation.md) — Enables injecting a provider instead of the created object, allowing components to produce new instances on demand. ([source](https://python-dependency-injector.ets-labs.org/tutorials/cli.html))
- [Provider Grouping](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/provider-grouping.md) — Groups several factories under a single provider and selects the active one based on a runtime key. ([source](https://python-dependency-injector.ets-labs.org/providers/factory.html))
- [Static Object Injection](https://awesome-repositories.com/f/software-engineering-architecture/dependency-injection-providers/static-object-injection.md) — Provides mechanisms to inject pre-defined objects or constant values exactly as they are into the dependency graph. ([source](https://python-dependency-injector.ets-labs.org/providers/object.html))
- [Dynamic Assembly Configurations](https://awesome-repositories.com/f/software-engineering-architecture/dynamic-function-injection/provider-configurations/dynamic-assembly-configurations.md) — Provides the ability to determine application structure at runtime via configuration files or external data. ([source](https://python-dependency-injector.ets-labs.org/containers/dynamic.html))
- [Runtime Configuration Overrides](https://awesome-repositories.com/f/software-engineering-architecture/runtime-configuration-overrides.md) — Replaces registered provider implementations at execution time to facilitate mocking and environment-specific configuration.

### DevOps & Infrastructure

- [Asynchronous Dependencies](https://awesome-repositories.com/f/devops-infrastructure/dependency-management/dependency-injection-systems/asynchronous-dependencies.md) — Resolves dependencies using awaitables to support non-blocking initialization and shutdown of shared resources.
- [Configuration Merging](https://awesome-repositories.com/f/devops-infrastructure/configuration-management/file-based-configuration/configuration-file-loading/configuration-merging.md) — Combines settings from multiple external sources like YAML, JSON, and environment variables into a unified registry.
- [Multi-Container Organization](https://awesome-repositories.com/f/devops-infrastructure/dependency-management/dependency-injection-containers/multi-container-organization.md) — Allows distributing object assembly across multiple declarative containers to manage complexity in large applications. ([source](https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html))
- [Package Dependency Decoupling](https://awesome-repositories.com/f/devops-infrastructure/dependency-management/dependency-injection-containers/package-dependency-decoupling.md) — Defines external dependencies within a package container using placeholders to maintain implementation agnosticism. ([source](https://python-dependency-injector.ets-labs.org/examples/decoupled-packages.html))
- [Provider Lifecycle Management](https://awesome-repositories.com/f/devops-infrastructure/self-hosted-applications/container-lifecycle-management/provider-lifecycle-management.md) — Manages the reset of singleton instances and copying of container states to control object instantiation. ([source](https://python-dependency-injector.ets-labs.org/containers/index.html))

### Programming Languages & Runtimes

- [Dependency Wiring Hooks](https://awesome-repositories.com/f/programming-languages-runtimes/importing-mechanisms/import-hook-installers/dependency-wiring-hooks.md) — Installs a module loader hook to automatically resolve and inject dependencies when modules are imported.
- [String-Based Class Import](https://awesome-repositories.com/f/programming-languages-runtimes/class-instantiation/string-based-class-import.md) — Resolves and instantiates objects using absolute or relative module path strings instead of direct class references. ([source](https://python-dependency-injector.ets-labs.org/providers/factory.html))
- [Dependency Argument Injection](https://awesome-repositories.com/f/programming-languages-runtimes/function-argument-passing/dependency-argument-injection.md) — Binds a specific function or callable object to a dependency to pass it into other services. ([source](https://python-dependency-injector.ets-labs.org/examples-other/password-hashing.html))
- [Dependency Injection Hooks](https://awesome-repositories.com/f/programming-languages-runtimes/importing-mechanisms/import-hook-installers/dependency-injection-hooks.md) — Implements import hooks to automatically wire containers to modules as they are dynamically imported. ([source](https://python-dependency-injector.ets-labs.org/wiring.html))
- [Dependency Placeholders](https://awesome-repositories.com/f/programming-languages-runtimes/syntactic-placeholders/dependency-placeholders.md) — Uses abstract placeholders to define required dependencies that must be concrete implementations before application assembly.

### Testing & Quality Assurance

- [Dependency Mocking](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking.md) — Replaces production dependencies with mocks or alternative implementations during test execution to isolate the system. ([source](https://python-dependency-injector.ets-labs.org/examples/aiohttp.html))
- [Test Isolation](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-isolation.md) — Allows replacing production service implementations with mocks or stubs during testing to isolate components.

### Data & Databases

- [Execution Scope Resource Management](https://awesome-repositories.com/f/data-databases/resource-management/resource-lifecycle-managers/execution-scope-resource-management.md) — Initializes and configures shared resources like logging, event loops, or thread pools for specific execution scopes. ([source](https://python-dependency-injector.ets-labs.org/))
- [Scope-Based Resource Cleanup](https://awesome-repositories.com/f/data-databases/resource-management/resource-teardown/scope-based-resource-cleanup.md) — Provides automated initialization and shutdown of resources when functions are called via function wiring. ([source](https://python-dependency-injector.ets-labs.org/providers/resource.html))

### Development Tools & Productivity

- [Dynamic Provider Switching](https://awesome-repositories.com/f/development-tools-productivity/dynamic-configuration-providers/dynamic-provider-switching.md) — Selects between different provider implementations at runtime based on a specific configuration value. ([source](https://python-dependency-injector.ets-labs.org/tutorials/cli.html))

### Web Development

- [Request Context Management](https://awesome-repositories.com/f/web-development/request-context-management.md) — Creates singletons scoped to specific execution contexts to ensure separate instances for each request. ([source](https://python-dependency-injector.ets-labs.org/providers/context_local_resource.html))
- [Web Framework Integrations](https://awesome-repositories.com/f/web-development/web-framework-integrations.md) — Passes request-scoped resources into handlers, views, and endpoints of web frameworks to simplify dependency management. ([source](https://python-dependency-injector.ets-labs.org/examples/index.html))
