Injector.py Apr 2026
from injector import Injector injector = Injector([MyModule()]) # Pass your modules here service = injector.get(Service) # Automatically creates Database and Service print(service.db.status) # "Connected" Use code with caution. Copied to clipboard
Instantiate the Injector and use it to retrieve your root object. injector.py
A guide to implementing injector.py revolves around three main abstractions: injector.py
from injector import inject class Database: def __init__(self): self.status = "Connected" class Service: @inject def __init__(self, db: Database): self.db = db Use code with caution. Copied to clipboard injector.py