--- id: dependency-injector version: "4.49.1" license: Copyright (c) 2024, Roman Mogylatov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:… (full text in the JSON record) license_treatment: permissive maintenance: active --- # dependency-injector — Dependency injection framework for Python License: permissive · Maintenance: active · Downloads: 8.4M/mo ## What it is and what it does Dependency Injector is a framework that centralizes how your application assembles and injects object dependencies. Instead of scattering object creation and wiring throughout your code, you declare all components and their relationships in a container, then use decorators or explicit calls to inject them where needed. This makes testing easier (you can override components with mocks), configuration cleaner (read from yaml, json, ini, environment, or pydantic), and the dependency graph explicit and auditable. The framework provides multiple provider types—Factory for creating new instances, Singleton for shared instances, Configuration for settings, Resource for lifecycle management (logging, event loops, thread pools), and Callable/Coroutine for wrapping functions. It integrates with Django, Flask, FastAPI, Aiohttp, and other frameworks via a wiring system that automatically injects dependencies into decorated functions and methods. Written in Cython for performance, it supports both synchronous and asynchronous injection and includes mypy-friendly typing stubs. Use it for: - Organize Flask or FastAPI applications by declaring all services (database, cache, API clients) in a container and injecting them into route handlers - Replace real API clients with mocks during testing by overriding providers without changing application code - Manage configuration across dev, stage, and production environments by reading from different sources and swapping implementations - Initialize and manage resources like database connections, thread pools, or event loops with automatic cleanup - Build decoupled multi-package applications where each package defines its own container and dependencies ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Dependency Injector is a dependency injection framework that assembles and injects object dependencies into functions and methods, supporting factories, singletons, configuration providers, and async injection. Yes. Dependency Injector is a mature, actively maintained framework (4907 stars, release 57 days ago, production-stable classifier) with zero known vulnerabilities, permissive licensing, and broad platform support. Install friction is moderate due to Cython compilation but well-mitigated by pre-built wheels. It is worth installing if you want explicit, testable dependency management in a non-trivial application; less essential for simple scripts or if you prefer implicit dependency resolution. ## Install pip install dependency-injector uv add dependency-injector poetry add dependency-injector ## Installing dependency-injector Before you install: Medium install friction due to compiled Cython wheels, but well-supported across platforms (Windows, macOS, Linux, including ARM64 and musl). Active maintenance with release 57 days ago and 4907 GitHub stars indicate stable, production-ready status. License in practice: BSD 3-Clause permissive license allows commercial use, modification, and distribution with minimal restrictions—standard for open-source frameworks. Quickstart: pip install dependency-injector from dependency_injector import containers, providers from dependency_injector.wiring import Provide, inject class Container(containers.DeclarativeContainer): service = providers.Singleton(MyService) @inject def main(service: MyService = Provide[Container.service]) -> None: service.do_work() container = Container() container.wire(modules=[__name__]) main() Verify before relying: - Whether Cython compilation overhead affects startup time in short-lived processes or serverless environments - Performance comparison with other DI frameworks in high-throughput scenarios - Maturity of async injection support relative to synchronous injection ## Package facts - License: Copyright (c) 2024, Roman Mogylatov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:… (full text in the JSON record) (permissive) - Python support: supports_current - Install friction: medium - Maintenance: active - Downloads: 8.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags dependency injection framework, inversion of control IoC, service container, factory singleton pattern, wiring dependencies into functions, configuration management, async dependency injection, dependency-injection, inversion-of-control, testing [View on SkillFed](https://skillfed.io/packages/dependency-injector) · [View on PyPI](https://pypi.org/project/dependency-injector/)