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 Python 3.7 and 3.8.
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()
Also supports dataclass of Python3.7+.
from dataclasses import dataclass
from pytidy.decorators import component, autowired_cls
@component
class Hello:
def say(self):
print("Hello")
@autowired_cls
@dataclass
class Injected:
instance: Hello
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytidy-0.4.0.tar.gz.
File metadata
- Download URL: pytidy-0.4.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2150addefa82c3f829681120dee2021bef3cca0b734d3ba7a53c9cf81b91d46
|
|
| MD5 |
ceaa1ad6e911f2afaf879d93954b44f9
|
|
| BLAKE2b-256 |
e15dbe5a8aaa74ce845f0b4428fda7cace7a55be7c6a4ab0b3d492016a9f11b6
|
File details
Details for the file pytidy-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pytidy-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1e870812f737720964e56852c4dab03b4887468cd19014bde0bffc38b5c56fd
|
|
| MD5 |
c62e8b2d738678f8f439367e0d76c743
|
|
| BLAKE2b-256 |
b460d97cd36dc686950dbce346ee86be797734ce3e2e7d6b53e5de30e12555a0
|