Skip to main content
Build Status Tests status Documentation Status Join the chat at https://gitter.im/Aigrefin/py3njection

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.

What if I want a singleton ?

@singleton
class ClassToInject:
    pass

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 : https://pypi.python.org/pypi/py3njection

Want to know more ?

A more complete documentation is available here : http://py3njection.readthedocs.org/en/latest/

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 !

Metadata

Release files for py3njection 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py3njection 1.4.1
File Size Uploaded Provenance
py3njection-1.4.1.tar.gz 3.1 kB Without provenance Details

Release files / py3njection-1.4.1.tar.gz

Download URL py3njection-1.4.1.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7dd1a0612ebdd9b6417419b68635de6cfa368c01c45f7a9a60f656b9d0307bc5
BLAKE2b-256 checksum
How to use checksums
f853f5aca6d3ad581fb784f952f335735bf2990a7ab27a28859e9274bcc59f4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for py3njection 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.4.1 This release

1 release file No provenance

1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page