Skip to main content

Functional dependency paradigm

Project description

supply-demand

PyPI version License

A Python library for dependency orchestration and “demand/supply” resolution (function DI).
Inspired by advanced dependency-injection/inversion control, it lets you register “supplier” functions by key/type, and lets any supplier demand values from others—allowing composition, overrides, and dependency graphs.


Features

  • Register “suppliers” (functions) for different types/keys
  • Compose suppliers & override them dynamically
  • Pass context (scope) through demands
  • Supports both, async and sync suppliers
  • Auto-manages dependency graph and supplier registry merging

Installation

pip install supply-demand

or

python -m pip install supply-demand

or

python3 -m pip install supply-demand

Quick Start

from supply_demand import supply_demand
import asyncio

async def value_supplier(data, scope):
    return 42

async def root_supplier(data, scope):
    answer = await scope.demand({"type": "value"})
    print("Supply chain returned:", answer)

suppliers = {"value": value_supplier}
asyncio.run(supply_demand(root_supplier, suppliers))

Example: Dependency Chain

async def A(data, scope):
    return 1

async def B(data, scope):
    a_val = await scope.demand({"type": "A"})
    return a_val + 5

async def root(data, scope):
    result = await scope.demand({"type": "B"})
    print("Result:", result)

suppliers = {"A": A, "B": B}
asyncio.run(supply_demand(root, suppliers))

Output: Result: 6


API

supply_demand(root_supplier, suppliers)

  • root_supplier: Callable (data, scope). The entry point.
  • suppliers: Dict of {type: supplier_func, ...}.

context.demand(props)

  • props["type"] — The supplier type to demand.
  • Can override suppliers, pass data, etc.

Advanced

Supports registry extension, override, additive/clear logic via:

scope.demand({
  "type": "X",
  "suppliers": {"add": {"X": custom_x_supplier}}
})

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supply_demand-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supply_demand-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file supply_demand-0.1.0.tar.gz.

File metadata

  • Download URL: supply_demand-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for supply_demand-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a800f73fe7f6794a758cbe3ea59d3c6aecdb7fe5363a506009f61282239f5f6
MD5 c7c42e7a6692e4489ee151bb842ccd4b
BLAKE2b-256 30d7bb3b889305633f9a807dd6a6c4190c7e10d658b9ea67ed703f412e1ec67c

See more details on using hashes here.

File details

Details for the file supply_demand-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: supply_demand-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for supply_demand-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fd43e4fc0811b0f291fd1e9f86ad68033bc2ca53dc5038ebeef2923e1dbe449
MD5 b0c8ec9f3da87b8dbdbc8f4a4b796d8f
BLAKE2b-256 7090e0131d104c3b7cbb905a9b8b3f34bf18f364b1b61c6fcfe0d451b357d03d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page