Bevy is a refreshingly simple dependency injection framework for Python. It's as simple as using the
bevy.inject decorator, the
bevy.dependency descriptor, and type hints to declare dependencies on your functions, methods, and class objects.
Install bevy using pip:
pip install bevy
Then, you only need to import the core functions from
from bevy import inject, dependency
Injecting Function Parameters
Bevy fully understands function parameters and will correctly handle positional only, positional, keyword, and keyword only arguments. It also understands what is being passed into the function and will only inject the dependencies that aren't already being passed.
from bevy import inject, dependency @inject def example(arg: Demo = dependency()): ...
Injecting Class Attributes
Bevy also understands class attributes and can inject them on class instances. To help keep instantiation, Bevy lazily inject dependencies on demand.
from bevy import dependency class Example: attr: Demo = dependency()
Check It Out
Bevy is available under an MIT license and you can see all the code on the GitHub.