Skip to main content

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

Release files for supply-demand 0.1.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 supply-demand 0.1.1
File Size Uploaded
supply_demand-0.1.1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supply-demand 0.1.1
File Interpreter ABI Platform
supply_demand-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / supply_demand-0.1.1.tar.gz

Download URL supply_demand-0.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8750082eb1f1eda9ba83d6fa28fbd36a4a0e2c1bc48de51d0496e05783c70f40
BLAKE2b-256 checksum
How to use checksums
4ecb18be441c0a056ea8ca8773a86ef957b6d0a6909ee5c9f04e9353c2cae6ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / supply_demand-0.1.1-py3-none-any.whl

Download URL supply_demand-0.1.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22e54efdbf12355c31785c3e83cbe2ad0bd9d9161d8788cc19b00433f40bb683
BLAKE2b-256 checksum
How to use checksums
f539f701b57dacffd2538d73fa3acfd2f76b1cc165f1789de97b74d9f6b46c10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.9

2 release files

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