Simple Dependency Injector for python
Project description
A simple async-friendly dependency injection framework for Python 3.
- Supports:
Async methods
Parametrized dependencies
Type annotations
Simple Example
import diana
class MyThing(object):
def __init__(self, prefix):
self.prefix = prefix
def get(self, suffix):
return self.prefix + suffix
class MyModule(diana.Module):
@diana.provider
def provide_thing(self) -> MyThing:
return MyThing("a_prefix_")
@diana.injector
def requires_a_thing(*, thing: MyThing):
return thing.get('suffix')
if __name__ == '__main__':
diana.injector.load_module(MyModule())
requires_a_thing() # returns "a_prefix_suffix"
Parametrized Dependencies
import diana
import typing
Snake = typing.NewType('Snake', str)
class SnakeModule(diana.Module):
@diana.provider
def provide_snake(self, length: int) -> Snake:
return Snake('-' + ('=' * length) + e)
@diana.inject(a_snake=Snake)
@diana.param('a_snake', length=5)
def snake_printer(a_snake):
print(a_snake, "Hissss")
if __name__ == '__main__':
diana.injector.load_module(SnakeModule())
snake_printer() # Prints: -=====e Hissss
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file diana-3.0.0b4-py3-none-any.whl
.
File metadata
- Download URL: diana-3.0.0b4-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab90ca7922aff3b77a2bfaf2f7be6ac2294f675df3fe8eb5145293378fe79f5 |
|
MD5 | aca7243d141b336720f92b4c07e3783f |
|
BLAKE2b-256 | 4b34a01452fe829c5b50519b4bc1630c1a6928f7ea2500843b80a8ece9d8cb4c |