Dependency Injection Container Library
Project description
Injecta
Dependency Injection (DI) Container written in Python. Main component of the Pyfony Framework.
Installation
$ pip install injecta
Simple container initialization
(The following steps are covered in the ContainerInitializerTest)
To start using Injecta, create a simple config.yaml file to define your DI services:
parameters:
api:
endpoint: 'https://api.mycompany.com'
services:
mycompany.api.ApiClient:
arguments:
- '@mycompany.api.Authenticator'
mycompany.api.Authenticator:
class: mycompany.authenticator.RestAuthenticator
arguments:
- '%api.endpoint%'
- '%env(API_TOKEN)%'
Then, initialize the container:
from injecta.container.ContainerBuilder import ContainerBuilder
from injecta.config.YamlConfigReader import YamlConfigReader
from injecta.container.ContainerInitializer import ContainerInitializer
config = YamlConfigReader().read('/path/to/config.yaml')
containerBuild = ContainerBuilder().build(config)
container = ContainerInitializer().init(containerBuild)
Use container.get() to finally retrieve your service:
from mycompany.api.ApiClient import ApiClient
apiClient = container.get('mycompany.api.ApiClient') # type: ApiClient
apiClient.get('/foo/bar')
Advanced examples
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 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 injecta-0.8.0b2.tar.gz.
File metadata
- Download URL: injecta-0.8.0b2.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0 CPython/3.7.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e0ba6dff84fbe295caf3dfa3f075fca33aa3ef2c7b83641fd91f8cb01d244e1
|
|
| MD5 |
6125d185e30ddad3f833f5ad8ab961f6
|
|
| BLAKE2b-256 |
bd6bd3ae517f8bd3665e929af44829a79edfb8e35b4301b7ae473c8cb2c40c1d
|
File details
Details for the file injecta-0.8.0b2-py3-none-any.whl.
File metadata
- Download URL: injecta-0.8.0b2-py3-none-any.whl
- Upload date:
- Size: 49.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0 CPython/3.7.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20ef46e1767d5592a92d086dfa5f65ef2ac57b6a0780a9c5d829895c57e8cf7d
|
|
| MD5 |
9d68f3c269dfbd69ae153232a2221a11
|
|
| BLAKE2b-256 |
9c6da2ae2efbffb97b0fa03a11bacf273b10a2795e434e0ac814742a6dec5f2e
|