Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A simple dependency injection module using python 3 annotations

Project Description

How to use

from py3njection import inject
from some_package import ClassToInject

class Demo:
    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.

What if I want a singleton ?

class ClassToInject:

That’s it ! When @inject sees a class with this decorator, it always uses the same instance.

How to install

It’s available on PyPI !

pip install py3injection

Or get it at :

Want to know more ?

A more complete documentation is available here :

Contact and Contribution

Feel free to contribute in any way :

Some Notes

  • Unit tests come easy to set up (unless you have too many dependencies, but that would be a code smell, right ?). Just 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 !
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
py3njection-1.4.1.tar.gz (3.1 kB) Copy SHA256 Checksum SHA256 Source Jun 20, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting