Skip to main content

simple-di

A simple, strictly typed dependency injection library.

mypy-strict

Python 3.6 Python 3.7 Python 3.8 Python 3.9

Install

    pip install simple_di

Usage

Examples:

    from simple_di import inject, Provide, Provider, container
    from simple_di.providers import Static, Factory, Configuration


    @container
    class OptionsClass(container):
        cpu: Provider[int] = Static(2)
        worker: Provider[int] = Factory(lambda c: 2 * int(c) + 1, c=cpu)

    Options = OptionsClass()

    @inject
    def func(worker: int = Provide[Options.worker]):
        return worker

    assert func() == 5
    assert func(1) == 1

    Options.worker.set(2)
    assert func() == 2

    Options.worker.reset()
    assert func() == 5

    Options.cpu.set(1)
    assert func() == 3

API

Type annotation supported

inject

Inject values into providers in function/method arguments.

Arguments:

  • squeeze_none: default False. Treat None value passed in as not passed.

Metadata

Release files for simple-di 0.1.5

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

Source distribution (sdist)

Source distribution for simple-di 0.1.5
File Size Uploaded Provenance Actions
simple_di-0.1.5.tar.gz 9.3 kB Without provenance Details for simple_di-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-di 0.1.5
File Interpreter ABI Platform Actions
simple_di-0.1.5-py3-none-any.whl Python 3 none any Details for simple_di-0.1.5-py3-none-any.whl

Total release size: 19.2 kB

Release files / simple_di-0.1.5.tar.gz

Download URL simple_di-0.1.5.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
192b999dee4cd4fb11a5d861165caad02d8f0617c0f806fc5b09f905f1a03ca0
BLAKE2b-256 checksum
How to use checksums
2ab8f2e3d1d6eac545c897a9b8ae339f2f2437a0e0b00bf0df3767109bede14d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.11

Release files / simple_di-0.1.5-py3-none-any.whl

Download URL simple_di-0.1.5-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3fb6242f18f389a3c2d571dd51ade47c74cdbc4550590894664ad59bfb2a345
BLAKE2b-256 checksum
How to use checksums
c56d02014c8b1e34bae98b9b7fb5e9a4bc17aecdc28dfb08083e1fa9e4731b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.11

Security for simple-di 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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