Injector
Pythonic dependency injection framework inspired by Google Guice
Repository Health
Technical Analysis
Injector is a dependency injection framework for Python, inspired by Google Guice. While Python’s keyword arguments and dynamic nature make manual dependency injection easy, Injector removes the boilerplate that accumulates in larger applications by automatically and transitively resolving dependencies for you and encouraging well-compartmentalised code through modules.
It is deliberately Pythonic and nonintrusive: constructors decorated for injection remain ordinary constructors you can still instantiate by hand, there is no global state so you can run many independently configured Injector instances, and the API is designed to cooperate with static type checkers wherever possible.
What You Get
- Automatic, transitive dependency resolution driven by type annotations
- Composable Module classes for organising and configuring bindings
- Scopes including singletons to control object lifetimes
- No global state — run as many independently configured Injector instances as you need
- A statically-typed API that cooperates with type checkers like mypy
- Nonintrusive design where injected constructors stay ordinary constructors
Common Use Cases
- Wiring services and repositories in larger Python applications
- Decoupling components to make them easier to test and mock
- Organising configuration and bindings into reusable modules
- Managing singleton and scoped object lifetimes across an app
Under The Hood
Architecture - Injector centers on the Injector container, which reads a set of Module configurations to build a binding registry mapping requested types to providers. When you call Injector.get or Injector.create_object, it inspects @inject-decorated constructors, resolves each parameter’s type transitively, applies the appropriate scope (e.g. singleton), and returns a fully constructed object graph. There is deliberately no global container, so lifetimes and configuration are always tied to a specific instance.
Tech Stack - The library is pure Python with no runtime dependencies, distributed on PyPI and documented on Read the Docs. It leans on standard type annotations for binding keys and integrates with static type checkers like mypy.
Code Quality - The project is long-established (created in 2010) with CI on GitHub Actions and coverage tracked via Codecov. Its stated core value of preferring a Pythonic API over faithful Guice replication keeps the surface area small and avoids excessive magic such as member or method injection.
API Design - The public API is intentionally minimal: decorate constructors with @inject, group bindings in Module subclasses, and retrieve instances with Injector.get. The nonintrusive design means annotated classes stay ordinary and can be instantiated manually, and the typed get method preserves static safety, keeping the learning curve modest for anyone familiar with DI concepts.