Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pypendency

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pypendency

A dependency injection tool for python

  • 0.5.0
  • PyPI
  • Socket score

Maintainers
2

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"

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc