Skip to main content

Usage Examples 🚩 | Developer Reference 👩‍💻 | Authors 👫

license

GitHub license

docs

Documentation

tests

Build Status Coverage Status Reliability Rating Security Rating Code Style Standards

package

PyPI Package latest release PyPI Wheel Supported versions Supported implementations Supported Platforms Downloads per Month

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

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],
        message_brokers: Annotated[List[Broker], Autowired],
    ):
        pending = database.get_pending_messages()
        for broker in message_brokers:
            broker.send_pending(pending)
from abc import ABC

class Broker(ABC):
    def send_pending(messages):
        ...
from injectable import injectable

@injectable
class Database:
    ...
from messaging import Broker
from injectable import injectable

@injectable
class KafkaProducer(Broker):
    ...
from messaging import Broker
from injectable import injectable

@injectable
class SQSProducer(Broker):
    ...

Features you’ll love ❤️

  • Autowiring: injection is transparent to the function. Just decorate the function with @autowired and annotate parameters with Autowired, that’s it.

  • Automatic dependency discovery: just call load_injection_container() at the root of your project or pass the root path as an argument. All classes decorated with @injectable will be automatically discovered and ready for injection.

  • Qualifier overloading: declare as many injectables as you like for a single qualifier or extending the same base class. You can inject all of them just by specifying a typing.List to Autowired: deps: Annotated[List["qualifier"], Autowired].

  • Transparent lazy initialization: passing the argument lazy=True for Autowired will make your dependency to be initialized only when actually used, all in a transparent fashion.

  • Singletons: decorate your class with @injectable(singleton=True) and only a single instance will be initialized and shared for injection.

  • Namespaces: specify different namespaces for injectables as in @injectable(namespace="foo") and then just use them when annotating your parameters as in dep: Annotated[..., Autowired(namespace="foo")].

  • Linters friendly: Autowired is carefully designed to comply with static linter analysis such as PyCharm’s to preserve the parameter original type hint.

These are just a few cool and carefully built features for you. Check out our docs!

Release files for injectable 4.0.1

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

Source distribution (sdist)

Source distribution for injectable 4.0.1
File Size Uploaded
injectable-4.0.1.tar.gz 31.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for injectable 4.0.1
File Interpreter ABI Platform
injectable-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.6 kB

Release files / injectable-4.0.1.tar.gz

Download URL injectable-4.0.1.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1f5b269d5560a8c34d1d7fdc5064acbb96e3a11ee79fe3cc7ea98dbfa35309dc
BLAKE2b-256 checksum
How to use checksums
2c8b53e3ff8255d4dc8efa7db135e51152575247cb3f54e8e38aaeba38621eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / injectable-4.0.1-py3-none-any.whl

Download URL injectable-4.0.1-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42f5879b78383c22127510ab7ff468651cae1f4cee1fae64aadccb1793658bec
BLAKE2b-256 checksum
How to use checksums
afb571150cbc179fcc2ca4e1bfcfd5ce583c9e3f27a2db1cc1a423484cb4c0bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files

4.0.0

2 release files

3.4.7

2 release files

3.4.6

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.3

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

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