Skip to main content

Dependency Injection Container Library

Project description


Dependency Injection (DI) Container written in Python. Main component of the Pyfony Framework.


$ 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:

    endpoint: ''

        - '@mycompany.api.Authenticator'

      class: mycompany.authenticator.RestAuthenticator
        - '%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   

Advanced examples

  1. Configuring services using parameters
  2. Service autowiring
  3. Using service factories
  4. Tagged services

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for injecta, version 0.10.0
Filename, size File type Python version Upload date Hashes
Filename, size injecta-0.10.0-py3-none-any.whl (58.3 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page