Skip to main content

Fast and easy dependency injection framework.

Project description

python-injection

CI PyPI Ruff

Fast and easy dependency injection framework.

Installation

⚠️ Requires Python 3.12 or higher

pip install python-injection

Motivations

  1. Easy to use
  2. No impact on class and function definitions
  3. Easily interchangeable dependencies (depending on the runtime environment, for example)
  4. No prerequisites

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()

Resources

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

python_injection-0.10.8.post0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

python_injection-0.10.8.post0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file python_injection-0.10.8.post0.tar.gz.

File metadata

  • Download URL: python_injection-0.10.8.post0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure

File hashes

Hashes for python_injection-0.10.8.post0.tar.gz
Algorithm Hash digest
SHA256 a4467548a828e307204a811f6ad0cfcd20025a0a201ef7688bc7c67d58c5d2d2
MD5 dd1a2879a7008c01cb3c8ac8ea9c660d
BLAKE2b-256 5817d040cfb07aaeaffc1a01735d08e524255b7e8f0ffbf58b4e85f109b1c778

See more details on using hashes here.

File details

Details for the file python_injection-0.10.8.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_injection-0.10.8.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e85b56231b5f53fbc5cca5e39f30eb17b07aaebf6af892171187aafae93569
MD5 9551472bd38d3b00d14150766b70d896
BLAKE2b-256 c33c0a776010263262daa542124cfb6da782e17ebe4396e6e21a3772ce02c7c4

See more details on using hashes here.

Supported by

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