Skip to main content

A dependency injection module using python 3 annotations

Project description

Build Status Tests status Documentation Status

How to use

from py3njection import inject
from some_package import ClassToInject

class Demo:
    @inject
    def __init__(self, object_to_use: ClassToInject):
        self.dependency = object_to_use

demo = Demo()

How does it work ?

The decorator @inject looks for any annotated method/function parameters (return annotation excluded).

It creates a new object from the specified class if no object is already provided.

How to install

It’s available on PyPI !

pip install py3injection

Some Notes

  • Unit tests come easy to set up (unless you have too many dependencies, but that would be a code smell, right ?). Juste specify mock instances at your object creation. Examples will come later.

  • This also means the injected object could also have some of its members injected too at their initialization !

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

py3njection-1.1.tar.gz (2.0 kB view details)

Uploaded Source

File details

Details for the file py3njection-1.1.tar.gz.

File metadata

  • Download URL: py3njection-1.1.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py3njection-1.1.tar.gz
Algorithm Hash digest
SHA256 7a6d4b2e83c906c8a1499f3531004fe2360182a7d0c2f2db6e27b689b1007bfa
MD5 3b27aa4c54ea51bd8fed1fb37e9e76b7
BLAKE2b-256 79deb1dd73121dcd37a2328f59d04e15caf063eda05a441b841cf1f489ce9854

See more details on using hashes here.

Supported by

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