supply-demand
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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| supply_demand-0.1.1.tar.gz | 4.2 kB | Without provenance | Details for supply_demand-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| supply_demand-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for supply_demand-0.1.1-py3-none-any.whl |
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
|
Security for supply-demand 0.1.1
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.