Dependency Injection library based on type hints
Project description
Pytidy
A type hint based dependency injection library for python language (+3.6). While there are already several DI libraries for python, this library is inspired by Java Spring and aims to provide similar interface and functionality to Java Spring.
Supports Python3.6+
Usage
Super simple. Attach @component
decorator to any classes which need to be injected in somewhere constructor, and attach @autowired
decorator to constructors which need dependency injection.
from pytidy.decorators import component, autowired
@component
class Hello:
def say(self):
print("Hello")
class Injected:
@autowired
def __init__(self, instance: Hello):
self.instance = instance
def say_proxy(self):
self.instance.say()
a = Injected()
a.say_proxy()
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytidy-0.3.0.tar.gz
(3.1 kB
view hashes)
Built Distribution
pytidy-0.3.0-py3-none-any.whl
(5.0 kB
view hashes)