roo-oliv / injectable

Python Dependency Injection for Humans™
https://injectable.readthedocs.io
MIT License
112 stars 9 forks source link
autowired autowiring circular-dependencies dependency-injection for-humans injection ioc lazy-evaluation micro-framework python

.. _injectable: .. role:: python(code) :language: python

Injectable: Dependency Injection for Humans™

Usage Examples 🚩 <https://injectable.readthedocs.io/en/latest/usage/index.html> | Developer Reference 👩‍💻 <https://injectable.readthedocs.io/en/latest/reference/index.html> | Authors 👫 <https://injectable.readthedocs.io/en/latest/authors.html>_

.. start-badges

.. list-table:: :stub-columns: 1

* - license
  - |license|
* - docs
  - |docs|
* - tests
  - |build| |coveralls| |reliability| |security| |black| |flake8|
* - package
  - |version| |wheel| |supported-versions| |supported-implementations| |platforms| |downloads|

.. |docs| image:: https://readthedocs.org/projects/pip/badge/?version=latest&style=plastic :target: https://injectable.readthedocs.io/en/latest/ :alt: Documentation

.. |build| image:: https://github.com/roo-oliv/injectable/actions/workflows/build.yml/badge.svg :alt: Build Status :target: https://github.com/roo-oliv/injectable/actions/workflows/build.yml

.. |coveralls| image:: https://coveralls.io/repos/github/allrod5/injectable/badge.svg?branch=master :alt: Coverage Status :target: https://coveralls.io/github/allrod5/injectable?branch=master

.. |reliability| image:: https://sonarcloud.io/api/project_badges/measure?project=roo-oliv_injectable&metric=reliability_rating :alt: Reliability Rating :target: https://sonarcloud.io/dashboard?id=roo-oliv_injectable

.. |security| image:: https://sonarcloud.io/api/project_badges/measure?project=roo-oliv_injectable&metric=security_rating :alt: Security Rating :target: https://sonarcloud.io/dashboard?id=roo-oliv_injectable

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg :alt: Code Style :target: https://github.com/psf/black

.. |flake8| image:: https://img.shields.io/badge/standards-flake8-blue :alt: Standards :target: https://flake8.pycqa.org/en/latest/

.. |version| image:: https://img.shields.io/pypi/v/injectable.svg :alt: PyPI Package latest release :target: https://pypi.org/project/injectable

.. |wheel| image:: https://img.shields.io/pypi/wheel/injectable.svg :alt: PyPI Wheel :target: https://pypi.org/project/injectable

.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/injectable.svg :alt: Supported versions :target: https://pypi.org/project/injectable

.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/injectable.svg :alt: Supported implementations :target: https://pypi.org/project/injectable

.. |license| image:: https://img.shields.io/github/license/roo-oliv/injectable :alt: GitHub license :target: https://github.com/roo-oliv/injectable/blob/master/LICENSE

.. |platforms| image:: https://img.shields.io/badge/platforms-windows%20%7C%20macos%20%7C%20linux-lightgrey :alt: Supported Platforms :target: https://github.com/roo-oliv/injectable/blob/master/.github/workflows/build.yml#L11

.. |downloads| image:: https://pepy.tech/badge/injectable/month :alt: Downloads per Month :target: https://pepy.tech/project/injectable/month

.. end-badges

Injectable is an elegant and simple Dependency Injection framework built with Heart and designed for Humans.

.. list-table:: :header-rows: 0

* - .. code:: python

        from typing import Annotated, List
        from injectable import Autowired, autowired
        from models import Database
        from messaging import Broker

        class Service:
            @autowired
            def __init__(
                self,
                database: Annotated[Database, Autowired],
                brokers: Annotated[List[Broker], Autowired],
            ):
                pending = database.get_pending_messages()
                for broker in brokers:
                    broker.send_pending(pending)

    .. code:: python

        from abc import ABC

        class Broker(ABC):
            def send_pending(messages):
                ...

  - .. code:: python

        from injectable import injectable

        @injectable
        class Database:
            ...

    .. code:: python

        from messaging import Broker
        from injectable import injectable

        @injectable
        class KafkaProducer(Broker):
            ...

    .. code:: python

        from messaging import Broker
        from injectable import injectable

        @injectable
        class SQSProducer(Broker):
            ...

Features you'll love ❤️

These are just a few cool and carefully built features for you. Check out our docs <https://injectable.readthedocs.io/en/latest/>_!