Skip to main content

Pypendency

Pypendency is a dependency injection library for python >=3.7.

Installation

pip install pypendency

Usage

Pypendency supports:

  • Declaration of explicit dependencies for each registered service.
  • Lazy evaluation (dependencies are not evaluated and instantiated until they are required)
  • Loading dependencies from different sources, such as python file, yaml file or directories. Also, it can be done programmatically.

Examples

# application_bootstrap.py

from pypendency.builder import container_builder
from pypendency.definition import Definition
from pypendency.loaders.yaml_loader import YamlLoader
from pypendency.loaders.py_loader import PyLoader

# Manually
container_builder.set('random_object', object())
container_builder.set_definition(
    Definition('another_random_object', 'builtins.object')
)

# File by file
YamlLoader(container_builder).load('/absolute/path/to/yaml/example.yaml')
PyLoader(container_builder).load('/absolute/path/to/python_file/example.py')
PyLoader(container_builder).load_by_module_name('python_file.example')

# Specifying a directory
YamlLoader(container_builder).load_dir('/absolute/path/to/yaml/')
PyLoader(container_builder).load_dir('/absolute/path/to/python_file/')
# path_to_yaml/example_di.yaml

example_class_identifier:
    fqn: example.class.namespace.ClassName
    args:
        - '@another_example_class_identifier'
    kwargs:
        example_kwarg: '@random_object'
# python/file/namespace/example_di.py

from pypendency.argument import Argument
from pypendency.builder import ContainerBuilder
from pypendency.definition import Definition


def load(container_builder: ContainerBuilder):
    container_builder.set("literal_string", "example_literal_string")
    container_builder.set_definition(
        Definition(
            "another_example_class_identifier",
            "another.example.class.namespace.AnotherClassName",
            [
                Argument.no_kw_argument("@literal_string"),
                Argument("kw_arg_example", "@literal_string"),
            ]
        )    
    )

Running tests

Build the docker image:

docker build . -t pypendency-dev

Run tests:

docker run -v $(pwd)/.:/usr/src/app pypendency-dev bash -c "pipenv run make run-tests"

Release files for pypendency 0.5.0

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

Source distribution (sdist)

Source distribution for pypendency 0.5.0
File Size Uploaded
pypendency-0.5.0.tar.gz 6.7 kB Details

Built distribution (wheel)

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

Total release size: 17.0 kB

Release files / pypendency-0.5.0.tar.gz

Download URL pypendency-0.5.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
38e28407d3d8e455b54f4b919986612609c5fbe506ce27c555ad715210dc5c09
BLAKE2b-256 checksum
How to use checksums
af9f127d9632f7c272880ad6fa2487a753ca97d548894fc7b8cf001827f04711
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Release files / pypendency-0.5.0-py3-none-any.whl

Download URL pypendency-0.5.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c72c6eb0ad8a780cc37b52773917ca6e314d1838c0588c22c2c7640c92b01946
BLAKE2b-256 checksum
How to use checksums
9e8a3a0cd5cb74802061d5963e763986b9bbe3726b4eb34f75d0188b9efcc8dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.16

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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