Skip to main content

python-injection

PyPI - Version PyPI - Downloads

Project motivations

Dependency injection in Python has long been a source of frustration.

Existing solutions are often verbose, require extensive boilerplate, or fail to leverage Python's type hints effectively. python-injection was created to solve these problems once and for all by providing a simple, elegant, and powerful dependency injection framework that feels natural to Python developers.

The goal is straightforward: make dependency injection so easy that you'll wonder how you ever managed without it.

Why choose python-injection?

  • Type-driven resolution: Dependencies are automatically resolved using Python's type annotations.
  • Decorator-based registration: Register your dependencies with simple, readable decorators.
  • Flexible lifetimes: Choose from four types of lifetimes to match your needs:
    • Transient: A new instance every time
    • Singleton: One instance for the entire application
    • Scoped: One instance per scope, with context manager support
    • Constant: A value created once and never re-resolved, either pre-existing or computed lazily
  • Profile support: Ability to swap certain dependencies based on a profile.
  • Pull-based instantiation: Dependencies registered with decorators are only created when needed, improving startup time and resource usage.
  • Full sync/async support: Works seamlessly with both synchronous and asynchronous code.

Installation

Requires Python 3.12 or higher.

pip install python-injection

Quick start

Simply apply the decorators and the package takes care of the rest.

from injection import injectable, inject, singleton


@singleton
class Printer:
    def __init__(self):
        self.history = []

    def print(self, message: str):
        self.history.append(message)
        print(message)


@injectable
class Service:
    def __init__(self, printer: Printer):
        self.printer = printer

    def hello(self):
        self.printer.print("Hello world!")


@inject
def main(service: Service):
    service.hello()


if __name__ == "__main__":
    main()

Metadata

Release files for python-injection 0.27.0.post0

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

Source distribution (sdist)

Source distribution for python-injection 0.27.0.post0
File Size Uploaded Provenance Actions
python_injection-0.27.0.post0.tar.gz 25.1 kB Without provenance Details for python_injection-0.27.0.post0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-injection 0.27.0.post0
File Interpreter ABI Platform Actions
python_injection-0.27.0.post0-py3-none-any.whl Python 3 none any Details for python_injection-0.27.0.post0-py3-none-any.whl

Total release size: 57.1 kB

Release files / python_injection-0.27.0.post0.tar.gz

Download URL python_injection-0.27.0.post0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
823cca34e91bee767b43e9f59029724f59542d0cc73dfd2c463d9bdcf1a9651a
BLAKE2b-256 checksum
How to use checksums
1a25453919ff9672d71399bcd45af99c7c829ba1b6f6c013b78aab51d4838cf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / python_injection-0.27.0.post0-py3-none-any.whl

Download URL python_injection-0.27.0.post0-py3-none-any.whl
Size 32.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a4c79762a16da43faf99b16f28f4339e15efe0dc2aea1a06a626a212a512129
BLAKE2b-256 checksum
How to use checksums
2e8cc7db200b0623500852fd49096a3a156a73f9299be82889425d29325ce880
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for python-injection 0.27.0.post0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.27.0.post0 This release

2 release files No provenance

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