# Diay - a dependency injection library
[](https://travis-ci.org/anlutro/diay.py)
[](https://pypi.org/project/diay)
[](https://opensource.org/licenses/MIT)
Diay is a [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection)/[inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control) library for Python 3.5 and higher. It leverages the type hints introduced in 3.5 to allow you to easily call functions or construct classes that require specific types of objects to function.
As an extremely basic and somewhat contrived example - the value of the library doesn't really come into play until you have fairly deeply nested dependencies - let's say you want to render a jinja2 template using some data from an API.
```python
injector = diay.Injector()
injector.set_instance(SomeConfigClass, my_config_object)
@injector.provider
def make_jinja_environment() -> jinja2.Environment:
return jinja2.Environment()
@injector.provider
def make_api_client(config: SomeConfigClass) -> some.APIclient:
return some.APIclient(config.api_token)
def render(j2env: jinja2.Environment, apiclient: some.APIclient):
data = apiclient.get('/some/data')
template = j2env.get_template('some-template.html.j2', data=data)
return template.render()
html = injector.call(render)
```
[](https://travis-ci.org/anlutro/diay.py)
[](https://pypi.org/project/diay)
[](https://opensource.org/licenses/MIT)
Diay is a [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection)/[inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control) library for Python 3.5 and higher. It leverages the type hints introduced in 3.5 to allow you to easily call functions or construct classes that require specific types of objects to function.
As an extremely basic and somewhat contrived example - the value of the library doesn't really come into play until you have fairly deeply nested dependencies - let's say you want to render a jinja2 template using some data from an API.
```python
injector = diay.Injector()
injector.set_instance(SomeConfigClass, my_config_object)
@injector.provider
def make_jinja_environment() -> jinja2.Environment:
return jinja2.Environment()
@injector.provider
def make_api_client(config: SomeConfigClass) -> some.APIclient:
return some.APIclient(config.api_token)
def render(j2env: jinja2.Environment, apiclient: some.APIclient):
data = apiclient.get('/some/data')
template = j2env.get_template('some-template.html.j2', data=data)
return template.render()
html = injector.call(render)
```
Metadata
Release files for diay 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| diay-0.1.3.tar.gz | 4.0 kB | Without provenance | Details |
Release files / diay-0.1.3.tar.gz
| Download URL | diay-0.1.3.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1f739bb29e7c36d22071fed6843b8ccfc717a015e402bcaa42db2a51e044f4d
|
|
BLAKE2b-256 checksum How to use checksums |
16703f0ef4762d9576bf7052d51cbbbb11e90b5c8fb5215bdb108d9d88405374
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.1 CPython/3.5.3
|
Security for diay 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.