Is there a framework equivalent to Guice (http://code.google.com/p/google-guice) for Python?
If you want a guice like (the new new like they say), I recently made something close in Python 3 that best suited my simple needs for a side project.
All you need is an @inject on a method (__init__ included of course). The rest is done through annotations.
from py3njection import inject
from some_package import ClassToInject
class Demo:
@inject
def __init__(self, object_to_use: ClassToInject):
self.dependency = object_to_use
demo = Demo()
https://pypi.python.org/pypi/py3njection
There is a somewhat Guicey python-inject project. It's quite active, and a LOT less code then Spring-python, but then again, I haven't found a reason to use it yet.
I recently released a neat (IMHO) micro library for DI in python:
https://github.com/suned/serum
If you prefer a really tiny solution there's a little function, it is just a dependency setter.
https://github.com/liuggio/Ultra-Lightweight-Dependency-Injector-Python
Enterprython is a small framework providing dependency-injection, building the object graph automatically based on type hints.
I like this simple and neat framework.
http://pypi.python.org/pypi/injector/
Dependency injection as a formal pattern is less useful in Python than in other languages, primarily due to its support for keyword arguments, the ease with which objects can be mocked, and its dynamic nature.
That said, a framework for assisting in this process can remove a lot of boiler-plate from larger applications. That's where Injector can help. It automatically and transitively provides keyword arguments with their values. As an added benefit, Injector encourages nicely compartmentalized code through the use of Module s.
While being inspired by Guice, it does not slavishly replicate its API. Providing a Pythonic API trumps faithfulness.