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.7.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file python_injection-0.10.7.tar.gz.

File metadata

  • Download URL: python_injection-0.10.7.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for python_injection-0.10.7.tar.gz
Algorithm Hash digest
SHA256 4225aaa1eda4e60c92df8189d9a8f9940209371fce02b9b0463d4dd724abcf97
MD5 12d0a05665b9e9530fba15f73a7d42e9
BLAKE2b-256 05431e07ceb8fdef0fabc5cd820cca2ffb5e4ab82a5d04688574843c9aa03ce9

See more details on using hashes here.

File details

Details for the file python_injection-0.10.7-py3-none-any.whl.

File metadata

  • Download URL: python_injection-0.10.7-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for python_injection-0.10.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1e55e8814cfddd9206177368bbde7173d57207a2d267bf5f7331faa8d620af08
MD5 9500eb00d348e9d2e3ea6afe41d1b646
BLAKE2b-256 9a1ba2b1aebc455bca9ddbec5958ec924a3094648485de9238348ce21b0056ca

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