Nanoinject
Nanoinject is a terrifically small and simple dependency injection container for Python 3.6+. Its' key features:
- Easy enough to use in five minutes.
- Configurable in code or config files.
- Pretty feature complete.
Installation
pip install nanoinject
Use guide
Dependency injection is a way to achieve Inversion of Control.
Use in code
class A:
value = 42
class B:
def __init__(self, a):
self.a = a
c = Container()
c.add('a', lambda c: A())
c.add('b', lambda c: B(c.get('a')))
assert 42 == c.get('b').a.value
Using configuration
It starts with declaring your services in YAML format:
values:
scalar_value: 42
services:
a:
class: A
module: example.a
dependencies:
- value:scalar_value
b:
class: B
module: example.b
dependencies:
- a
And then letting the config object configure the container based on that YAML file:
import os
from nanoinject import Container, Config
class A:
def __init__(self, value):
self.value = value
class B:
def __init__(self, a):
self.a = a
c = Container()
config = Config.from_yaml_file(os.path.dirname(__file__) + '/services.yaml')
config.config(c)
assert 42 == c.get('b').a.value
Metadata
Release files for nanoinject 1.0.1
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 | Actions |
|---|---|---|---|---|
| nanoinject-1.0.1.tar.gz | 3.3 kB | Without provenance | Details for nanoinject-1.0.1.tar.gz |
Release files / nanoinject-1.0.1.tar.gz
| Download URL | nanoinject-1.0.1.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4bb4a9aa610fad768a9918bc39f00b547bc42e8d6d4957c33db51e618f3cfd5
|
|
BLAKE2b-256 checksum How to use checksums |
7c171c55187ae6fb2297e7a0f17a94c71c3b8c034d052459ce54e08923f5bec5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
|
Security for nanoinject 1.0.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.