Metadata-Version: 2.1
Name: pypendency
Version: 0.0.2
Summary: A dependency injection tool for python
Home-page: https://github.com/Feverup/pypendency
Author: Marcos Hernandez Juarez
Author-email: marcos.hernandez@feverup.com
License: MIT License
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: pyyaml
Requires-Dist: dataclasses

# Pypendency
Pypendency is a dependency injection library for python 3.6+.

## Installation
```bash
pip install pypendency
```

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

#### Examples

```python
# 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

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

YamlLoader(container_builder).load('path_to_yaml/example_di.yaml')
PyLoader(container_builder).load('python.file.namespace.example_di')
```

```yaml
# 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
# 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:
```bash
docker build . -t pypendency-dev
```

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


