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

Uploaded Source

Built Distribution

python_injection-0.10.3-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_injection-0.10.3.tar.gz
  • Upload date:
  • Size: 14.0 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.3.tar.gz
Algorithm Hash digest
SHA256 952a602ceb6c9e14c742bf51d0e768056d4bd225b778d34fe37c297f7aaed1f9
MD5 edc33a9a1c284281e69b6ef702775937
BLAKE2b-256 1db99642c39a7a0046f9433b93aa28f9b2344947074659807e8485a65215ec4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_injection-0.10.3-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 49b0d807dbdfaeb25951dec4db998511e2201a9a99c60cd3a8b01477dc5aeb53
MD5 6c7f5e6dd4275ce31bba53abfd570a9d
BLAKE2b-256 0fff186a714bcd8b7d8f8a70f9918a7180526da8ad270457cd924ae730689973

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