🌐
Ets-labs
python-dependency-injector.ets-labs.org
Dependency Injector — Dependency injection framework for Python — Dependency Injector 4.49.1 documentation
from dependency_injector import ... timeout=config.timeout, ) service = providers.Factory( Service, api_client=api_client, ) @inject def main(service: Service = Provide[Container.service]) -> None: ......
🌐
GitHub
github.com › python-injector › injector
GitHub - python-injector/injector: Python dependency injection framework, inspired by Guice · GitHub
Providing a Pythonic API trumps faithfulness. Additionally some features are omitted because supporting them would be cumbersome and introduce a little bit too much "magic" (member injection, method injection). Connected to this, Injector tries to be as nonintrusive as possible. For example while you may declare a class' constructor to expect some injectable parameters, the class' constructor remains a standard constructor – you may instantiate the class just the same manually, if you want.
Starred by 1.5K users
Forked by 95 users
Languages   Python
🌐
PyPI
pypi.org › project › injector
injector · PyPI
Providing a Pythonic API trumps faithfulness. Additionally some features are omitted because supporting them would be cumbersome and introduce a little bit too much "magic" (member injection, method injection). Connected to this, Injector tries to be as nonintrusive as possible. For example while you may declare a class' constructor to expect some injectable parameters, the class' constructor remains a standard constructor – you may instantiate the class just the same manually, if you want.
      » pip install injector
    
Published   Jan 09, 2026
Version   0.24.0
🌐
Ets-labs
python-dependency-injector.ets-labs.org › introduction › di_in_python.html
Dependency injection and inversion of control in Python — Dependency Injector 4.49.1 documentation
The example shows how to use providers’ overriding feature of Dependency Injector for testing or re-configuring a project in different environments and explains why it’s better than monkey-patching.
🌐
PyPI
pypi.org › project › inject
inject · PyPI
# Import the inject module. import inject # `inject.instance` requests dependencies from the injector. def foo(bar): cache = inject.instance(Cache) cache.save('bar', bar) # `inject.params` injects dependencies as keyword arguments or positional argument. # Also you can use @inject.autoparams in Python 3.5, see the example above.
      » pip install inject
    
Published   Jun 20, 2025
Version   5.3.0
🌐
GitHub
github.com › ets-labs › python-dependency-injector
GitHub - ets-labs/python-dependency-injector: Dependency injection framework for Python · GitHub
from dependency_injector import ... = providers.Factory( Service, api_client=api_client, ) @inject def main(service: Service = Provide[Container.service]) -> None: ......
Author   ets-labs
🌐
Readthedocs
injector.readthedocs.io
Injector 0.24.0 documentation
You need to be explicit and use Injector.get, Injector.create_object or inject MyClass into the place that needs it. Cooperation with static type checking infrastructure – the API provides as much static type safety as possible and only breaks it where there’s no other option. For example the Injector.get method is typed such that injector.get(SomeType) is statically declared to return an instance of SomeType, therefore making it possible for tools such as mypy to type-check correctly the code using it.
🌐
Medium
medium.com › @pavlomorozov78 › dependency-injection-in-python-with-injector-7ce7cab9d7f4
Dependency Injection in Python with Injector | by Pavlo Morozov | Medium
November 21, 2023 - The DeveloperNote attribute in ... the data. Here running application output in case of default profile: $ python3 injector_example_main.py --Profile default Fundamentals data DeveloperNote: None...
🌐
DataCamp
datacamp.com › tutorial › python-dependency-injection
Python Dependency Injection: A Guide for Cleaner Code Design | DataCamp
May 7, 2026 - The Provide class tells the dependency-injector which dependency to inject. This approach eliminates the need for manual wiring dependencies from the container. It’s helpful in larger applications where services may depend on multiple components (hence this need to initialize them automatically). Most modern Python frameworks make it easy to work with dependency injection, allowing you to write cleaner and more testable code.
Find elsewhere
🌐
Medium
medium.com › @garzia.luke › injector-library-and-exploring-dependency-injection-in-python-4ce10560cd24
Injector Library and Exploring Dependency Injection in Python | by Luke Garzia | Medium
February 8, 2024 - Here are the high-level abstractions for reference. The inject decorator registers dependencies. Module class creates implementations and defines binding. The Application will instantiate and call the Injector to create all objects.
🌐
Readthedocs
injector.readthedocs.io › en › latest › api.html
Injector API reference - Injector 0.24.0 documentation
Requires Python 3.9+. ... If you’re using mypy you need the version 0.750 or newer to fully type-check code using this construct. ... An unscoped provider. ... Provides class instances. class injector.ProviderOf(injector: Injector, interface: Type[T])¶
🌐
Stack Overflow
stackoverflow.com › questions › 65525227 › replicating-guide-named-with-python-injector-module
dependency injection - Replicating Guide @Named with Python injector module - Stack Overflow
Here's a full working example tested on python 3.6: Copyfrom injector import Injector, inject, Module, singleton, provider from typing_extensions import Annotated from typing import NewType, Callable # You can use Greeting instead of Annotated[str, 'greeting'] as it's the same type Greeting = Annotated[str, 'greeting'] class Greeter: @inject def __init__(self, greeting: Annotated[str, 'greeting']): self.greeting = greeting def greet(self): print(self.greeting) class MyModule(Module): def configure(self, binder): binder.bind(Greeting, to='Howdy', scope=singleton) binder.bind(str, to='Hello', scope=singleton) def main(): injector = Injector([MyModule()]) greeter = injector.get(Greeter) greeter.greet() if __name__ == '__main__': main()
🌐
Medium
medium.com › @rmogylatov › dependency-injector-python-dependency-injection-framework-eeb9f5c6db8b
Dependency Injector — Python dependency injection framework | by Roman Mogylatov | Medium
September 10, 2020 - That’s how the previous example will look like with a multiple containers approach: import logging.config import sqlite3 import boto3 from dependency_injector import containers, providers from .
🌐
Medium
medium.com › @spraneeth4 › python-dependency-injector-simplifying-dependency-injection-in-your-projects-14385af0bf78
Python Dependency Injector: Simplifying Dependency Injection in Your Projects | by praneeth_vvs | Medium
September 27, 2024 - To effectively integrate dependency injection using the Dependency Injector framework in a FastAPI application, two critical steps need to be implemented: container.wire(modules=[…]) — It Registers Modules: You’re telling the DI container which Python modules (or files) contain components that should have dependencies injected into them.
🌐
GitHub
github.com › ivankorobkov › python-inject
GitHub - ivankorobkov/python-inject: Python dependency injection
# Import the inject module. import inject # `inject.instance` requests dependencies from the injector. def foo(bar): cache = inject.instance(Cache) cache.save('bar', bar) # `inject.params` injects dependencies as keyword arguments or positional argument. # Also you can use @inject.autoparams in Python 3.5, see the example above.
Starred by 755 users
Forked by 85 users
Languages   Python 98.3% | Makefile 1.7% | Python 98.3% | Makefile 1.7%
🌐
Medium
medium.easyread.co › cleaner-more-maintainable-python-code-with-dependency-injector-fc290b52de10
Cleaner, More Maintainable Python Code with Dependency-Injector | by Ferdina Kusumah | Easyread
July 16, 2024 - This when dependency injection come to save, let’s refactoring our code to make it high cohesion and decoupled. To achieve this we will use famous dependency injector from python called python-dependency-injector this will help us to prepare all dependency to our code.
🌐
PyPI
pypi.org › project › python-injector
python-injector · PyPI
git clone https://github.com/mjdarvishi/python_injector cd python_injector pip install . ... Usage Registering Dependencies To register a class or service with the injector, you need to define a factory function that creates instances of the class. This is done using the Injector.register method. from injector import Injector # Example classes class Repository: pass class RepositoryImpl(Repository): pass # Registering the implementation of the Repository injector = Injector() injector.register(Repository, lambda: RepositoryImpl()) # Retrieving an instance of ShopRepository repo = injector.get(Repository)
      » pip install python-injector
    
Published   Mar 24, 2025
Version   0.2
🌐
Medium
medium.com › illuin › dependency-injection-made-easy-in-python-45ece11efeca
Dependency injection made easy in Python | by Thomas Richard | Illuin | Medium
October 21, 2020 - Note that you can still add bindings on top of the modules in your injector. ... Can you do better ? You talked about reducing boilerplate code, yet I still have to write all those bindings ? ... When using the auto_bindings option, classes are automatically bound to themselves, so you only need to write the other bindings. You can still use modules and bindings of course, these auto bindings are only created as a last resort option. In the example we removed the ChatModule since it contained only ClassBindings.
🌐
DEV Community
dev.to › sxddhxrthx › introduction-to-dependency-injection-in-python-35c
Introduction to Dependency Injection in Python - DEV Community
March 20, 2021 - import sys from dependency_injector import containers, providers from dependency_injector.wiring import inject, Provide class School: def __init__(self, name: str, city: str, board: str): self.schoolname = name self.city = city self.board = board def get_schoolname(self): print(f"school name is {self.schoolname}") class Student(): def __init__(self, name: str, age: int, grade: int, school: School): self.name = name self.age = age self.grade = grade self.school = school #super().__init__(school, city, board) def get_students(self): student_detail = f""" Student Name: {self.name} Student Age: {s