Skip to main content

A Simple PYthon Dependency Injection Library

Project description

Simple PYthon Dependepncy Injection Library (SPYDI)

What the hell is it?

A dependency injection library which is intended to utilize python's type annotations to build the dependency tree. No attempt has been made to optimize it since the only intended usage is right on app start so a slight slowness is acceptable in the majority of cases.

Motivation

A brief research has shown there is no such library in the whole internet. Other solutions either:

  • Rely on manual binding-by-name;
  • Requires deep integration into a source code;
  • Do not play well with python async features and context-managed dependencies;
  • Do not work with my beloved typing.NamedTuple;
  • Doesn't work at all;

How to use it

SPYDI does not require a deep integration into your application. Just design your app following the SOLID principles and SPYDI will handle the binding for you. A brief example could be found here (or refer to tests)

import typing

from spydi.context import DependencyContext
from spydi.factory import DependencyFactory


class Foo(typing.NamedTuple):
    a: int
    b: int
    c: str


def try_create_me(foo: Foo, bar):
    return foo.c + bar


ctx = DependencyContext()
ctx.bind(2, to='a')
ctx.bind(3, to='b')
ctx.bind('qwe', to='c')
ctx.bind('rty', to='bar')

factory = DependencyFactory(ctx)
result = factory.create(try_create_me)
assert result == 'qwerty'

Licensing

This project is licensed under Apache 2.0 License

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

spy-di-0.4.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spy_di-0.4.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file spy-di-0.4.0.tar.gz.

File metadata

  • Download URL: spy-di-0.4.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for spy-di-0.4.0.tar.gz
Algorithm Hash digest
SHA256 71ba813753d09396c6c2bdd10590fa968a5d3bc0041724fe25e4968ee52b42c5
MD5 dbdfd66bfef3c9df7bcabfaa2baf98cb
BLAKE2b-256 b55b469bc2449cda7ddebfd0fd76d96f8563d1ab9203c0755c1c840213421eb0

See more details on using hashes here.

File details

Details for the file spy_di-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: spy_di-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

File hashes

Hashes for spy_di-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da28dfbc6bb704e74f2b264d3dccd481871a42ab94e15e2fad2db0fa91d83891
MD5 0c2686cc63bf9c30a5bf37d02d4724af
BLAKE2b-256 cef58a6a71ffc7fdc5ea6ddddca6bf703df03f2561fe71f3ce2a7dadd15f1ec8

See more details on using hashes here.

Supported by

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