{"id":27235,"library":"pinject","title":"Pinject","description":"A pythonic dependency injection library for Python, inspired by Guice. Current version is 0.15.3 (last release on PyPI 0.14.1 but GitHub has 0.15.3). Development appears to be in maintenance mode with no recent releases.","status":"maintenance","version":"0.15.3","language":"python","source_language":"en","source_url":"https://github.com/google/pinject","tags":["dependency-injection","di","guice","inversion-of-control"],"install":[{"cmd":"pip install pinject","lang":"bash","label":"Latest stable"}],"dependencies":[],"imports":[{"note":"Common but unnecessary to import the whole module","wrong":"import pinject\nnew_object_graph = pinject.new_object_graph","symbol":"new_object_graph","correct":"from pinject import new_object_graph"},{"note":"@injectable is deprecated since v0.10, use @inject","wrong":"from pinject import injectable","symbol":"inject","correct":"from pinject import inject"},{"note":"Correct class is BindingSpec, not binding_spec","wrong":"from pinject import binding_spec","symbol":"BindingSpec","correct":"from pinject import BindingSpec"}],"quickstart":{"code":"import pinject\n\nclass MyClass:\n    @pinject.inject()\n    def __init__(self, dep):\n        self.dep = dep\n\nclass DepClass:\n    pass\n\nobj_graph = pinject.new_object_graph(binding_specs=[], modules=[DepClass])\nobj = obj_graph.provide(MyClass)\nprint(obj.dep.__class__.__name__)  # DepClass","lang":"python","description":"Demonstrates basic injection: MyClass depends on DepClass; Pinject automatically injects the dependency."},"warnings":[{"fix":"Use Python 3.11 or earlier, or switch to an actively maintained DI library like 'inject' or 'dependency-injector'.","message":"Pinject does not support Python 3.12+ due to removal of inspect.getargspec and other deprecated APIs. Pinject relies on inspect module details that are removed in Python 3.12.","severity":"gotcha","affected_versions":">=0.15.3"},{"fix":"Replace @pinject.injectable with @pinject.inject() (note the parentheses).","message":"@injectable decorator is deprecated since v0.10. Use @inject instead.","severity":"deprecated","affected_versions":">=0.10"},{"fix":"If you relied on default method names like 'configure', they still work. Only breaking if you overrode them and expected the old behavior.","message":"In v0.10, the default method names for BindingSpec were changed. Custom names can be set via 'configure_method_name' and 'dependencies_method_name' in new_object_graph.","severity":"breaking","affected_versions":"0.10 to 0.15.3"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use @pinject.inject() instead of @pinject.injectable.","cause":"Using deprecated @injectable decorator which was removed or aliased.","error":"AttributeError: module 'pinject' has no attribute 'injectable'"},{"fix":"Make sure you import correctly: from pinject import new_object_graph","cause":"Trying to invoke a module as a function, e.g., pinject.new_object_graph() but imported pinject incorrectly.","error":"TypeError: 'module' object is not callable"},{"fix":"Use @pinject.inject() (with parentheses) on the __init__ method.","cause":"Incorrectly using @inject without parentheses. @inject is a function that returns a decorator, so you need @inject() with parentheses.","error":"TypeError: object() takes no arguments"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}