--- id: inject version: "5.5.0" license: Apache-2.0 license_treatment: permissive maintenance: active --- # inject — Python dependency injection framework. License: permissive · Maintenance: active · Downloads: 2.3M/mo ## What it is and what it does Inject is a dependency injection framework that decouples object creation from usage by automatically wiring dependencies into functions and classes. It uses type annotations or explicit binding declarations to resolve and inject dependencies at runtime. The framework does not intercept or modify class constructors, instead offering decorators like @autoparams and @params, instance attributes via inject.attr, and direct instance retrieval via inject.instance. The package supports multiple binding strategies: instance bindings (always return the same object), constructor bindings (create singletons on first injection), and provider bindings (call a function on each injection). It integrates transparently with tests through configuration clearing, handles context managers, and is thread-safe after initial configuration. Runtime binding can be disabled to catch unbound dependencies early. Use it for: - Decouple service implementations from their consumers in web frameworks or CLI applications by binding interfaces to concrete implementations. - Simplify test setup by configuring mock dependencies without modifying production code or class constructors. - Manage shared resources like database connections or caches across an application by binding them once and injecting where needed. - Build modular applications where different environments (dev, test, production) use different implementations of the same interface. - Reduce boilerplate in class hierarchies by using inject.attr to declare dependencies as class properties instead of constructor parameters. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a lightweight dependency injection framework for Python that automatically injects dependencies into functions and classes using type annotations or explicit binding declarations. Yes. Inject is a mature, actively maintained dependency injection framework with no external dependencies, permissive licensing, and no known vulnerabilities. It is well-suited for Python projects that need lightweight, non-invasive dependency management. Install it if you want a simple alternative to heavier frameworks; skip it if your project already uses a framework with built-in DI (Django, FastAPI) or if you prefer explicit parameter passing. ## Install pip install inject uv add inject poetry add inject ## Installing inject Before you install: Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release 32 days ago; repo shows 774 stars and last commit on 2026-07-27. Requires Python 3.10+. License in practice: Apache-2.0 permissive license allows commercial and private use with minimal restrictions; suitable for most projects. Quickstart: pip install inject import inject @inject.autoparams def my_function(cache: RedisCache): pass def config(binder): binder.bind(RedisCache, RedisCache('localhost:1234')) inject.configure(config) my_function() # cache is automatically injected Requires Python 3.10 or later; type annotations are required for autoparams decorator to work. Verify before relying: - Whether the package's thread-safety guarantees hold under all concurrent binding scenarios - Performance characteristics when managing large dependency graphs or high-frequency injection calls ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 2.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags dependency injection python, autoparams type annotations, inversion of control framework, inject decorator, service locator pattern, bind dependencies python, thread-safe di container, dependency-injection, inversion-of-control, testing [View on SkillFed](https://skillfed.io/packages/inject) · [View on PyPI](https://pypi.org/project/inject/)