$ show ets-labs/python-dependency-injector
The Dependency Injector is a mature, feature-rich dependency injection framework for Python. It provides core DI patterns through providers (Factory, Singleton, Resource, etc.), containers (Declarative/Dynamic), and wiring mechanisms (@inject decorator). The framework emphasizes explicit dependency declaration, testability, and loose coupling while supporting async/await, configuration management from multiple sources, and runtime provider overriding. It includes framework-specific integrations (Flask, Django, FastAPI, etc.) via its wiring module and extension system, though the core remains framework-agnostic. Architecturally, the codebase separates concerns into distinct modules: providers handle object creation/lifecycle, containers manage provider resolution and hierarchy, wiring enables automatic dependency injection into functions/methods, resources manage lifecycle-dependent objects (e.g., DB connections), and configuration providers unify settings from YAML/INI/JSON/env. The framework uses Cython for performance-critical components while maintaining a pure Python interface. Comprehensive documentation, extensive test suite, and numerous examples demonstrate practical integration patterns across web applications, daemons, and cloud services. The project shows strong maintenance with frequent releases, active issue triage, and broad Python version support (3.8-3.14). Technical drift is low due to proactive dependency updates, removal of deprecated Python versions, and adherence to modern Python practices. The codebase exhibits high craftsmanship in its provider patterns, particularly the Resource provider's context-manager semantics and the wiring module's automatic dependency resolution, making it a reusable dependency injection solution for Python applications.
The LLM identified 3 files worth highlighting for reuse:
Implements the Resource provider for managing lifecycle-dependent objects (e.g., database connections, file handles) with setup/teardown logic. Supports synchronous/asynchronous resources, context manager protocol, and singleton scoping. Demonstrates non-obvious skill in handling resource lifecycle edge cases (e.g., exception safety, async cleanup) while providing a clean, reusable pattern for safe resource handling in any application.
Provides the @inject decorator and Provide/Provider markers for automatic dependency injection into functions and methods. Eliminates manual container lookup by resolving dependencies from wired containers at call time. Shows craftsmanship in handling bound methods, class methods, and async functions while maintaining explicit dependency declarations. Highly reusable for reducing boilerplate in application code without sacrificing testability.
Implements a unified configuration provider loading settings from YAML, INI, JSON, environment variables, and nested sources. Features automatic type conversion (int, float, Decimal, bool), required field validation, custom validators, and environment variable interpolation. Demonstrates non-obvious skill in handling configuration hierarchy, type safety, and error reporting while providing a reusable pattern for managing application settings across environments.