Skip to main content

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

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

Metadata

Release files for injecta 0.10.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for injecta 0.10.2
File Interpreter ABI Platform
injecta-0.10.2-py3-none-any.whl Python 3 none any Details

Release files / injecta-0.10.2-py3-none-any.whl

Download URL injecta-0.10.2-py3-none-any.whl
Size 59.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
544d237424a9d271eedee4987c9524a6100ed836d94548c05c94d1bc1c8a7c2e
BLAKE2b-256 checksum
How to use checksums
3faa71458f7c5cc0aec157df4e3dc31a65f6e6ad4a92f5b8bf1ff0a58d61f1cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.3 Linux/5.11.0-1028-azure

Release history Release notifications | RSS feed

This release

0.10.2 This release

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.3

2 release files

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.12

1 release file

0.8.11

1 release file

0.8.10

1 release file

0.8.9

1 release file

0.8.8

1 release file

0.8.7

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.7

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page