Skip to main content

Simple and functional dependency injection toolkit for Python

Project description

PyPI PyPI - Python Version PyPI - License PyPI - Downloads codecov

PyDio

Simple and functional dependency injection toolkit for Python.

About

PyDio aims to be simple, yet still powerful, allowing you to feed dependencies inside your application in a flexible way. PyDio design is based on simple assumption, that dependency injection can be achieved using simple key-to-function map, where key specifies type of object you want to inject and function is a factory function that creates instances of that type.

In PyDio, this is implemented using providers and injectors. You use providers to configure your key-to-function mapping, and then you use injectors to perform a lookup of a specific key and creation of the final object.

Here's a simple example:

import abc

from pydio.api import Provider, Injector

provider = Provider()

@provider.provides('greet')
def make_greet():
    return 'Hello, world!'

def main():
    injector = Injector(provider)
    greet_message = injector.inject('greet')
    print(greet_message)

if __name__ == '__main__':
    main()

Now you can save the snippet from above as example.py file and execute to see the output:

$ python example.py
Hello, world!

Key features

  • Support for any hashable keys: class objects, strings, ints etc.
  • Support for any type of object factories: function, coroutine, generator, asynchronous generator.
  • Automatic resource management via generator-based factories (similar to pytest's fixtures)
  • Multiple environment support: testing, development, production etc.
  • Limiting created object's lifetime to user-defined scopes: global, application, use-case etc.
  • No singletons used, so there is no global state...
  • ...but you still can create global injector on your own if you need it :-)

Installation

You can install PyDio using one of following methods:

  1. From PyPI (for stable releases):

    $ pip install PyDio
    
  2. From test PyPI (for stable and development releases):

    $ pip install -i https://test.pypi.org/simple/ PyDio
    
  3. Directly from source code repository (for all releases):

    $ pip install git+https://gitlab.com/zef1r/PyDio.git@[branch-or-tag]
    

Documentation

You have two options available:

  1. Visit PyDio's ReadTheDocs site.

  2. Take a tour around functional tests.

License

This project is released under the terms of the MIT license.

See LICENSE.txt for more details.

Author

Maciej Wiatrzyk maciej.wiatrzyk@gmail.com

Project details


Download files

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

Source Distribution

pydio-0.4.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

pydio-0.4.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file pydio-0.4.1.tar.gz.

File metadata

  • Download URL: pydio-0.4.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for pydio-0.4.1.tar.gz
Algorithm Hash digest
SHA256 3034a3d3227acf121af8dedccb638baf0970dc6383a71d90e74daa7697e9a96b
MD5 5e61f47f63b3ee7e54207403c396b4b6
BLAKE2b-256 2444d0eb2f9d54d32eea446f80c471dbabfc6fb9e6b45c590ee2bbbe4abf4a54

See more details on using hashes here.

File details

Details for the file pydio-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pydio-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.16

File hashes

Hashes for pydio-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8af3df9804feaefe6e540aebb11b5f83ca8e32eba7babf52c32a88963932df16
MD5 982bb089d46f64b9837fa804d28345e1
BLAKE2b-256 54bd9f72b6743879b38dab8be599401396c90b354b624e5f14427634b05320c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page