Declarative async pipelines with fan-out, fan-in, and built-in provenance
Project description
Special Week
Declarative async pipelines with fan-out, fan-in, and built-in provenance.
Nodes declare their own antecedents. The graph infers topology, runs everything concurrently, and attaches a full provenance chain to every result.
Installation
pip install specialweek
Demo
Fetch 20 XKCD comics, extract the first word of each title, and look every word up in a dictionary; all in parallel, declared as a single pipeline:
import asyncio
import time
from specialweek import Graph, Source, HTTP, Transform
# Fan-out: 20 items flow through the whole pipeline concurrently.
source = Source(*[{"id": str(i)} for i in range(2630, 2650)])
fetch_comic = HTTP(
"xkcd",
url="https://xkcd.com/${id}/info.0.json",
extract=lambda r: {"id": r["num"], "title": r["safe_title"]},
on_error={404: lambda _: {"id": None, "title": "(not found)"}},
depends_on=[source],
)
first_word = Transform(
"word",
fn=lambda v: {"word": v["title"].split()[0].lower(), "title": v["title"], "id": v["id"]},
depends_on=[fetch_comic],
)
define = HTTP(
"dictionary",
url="https://api.dictionaryapi.dev/api/v2/entries/en/${word}",
extract=lambda r: r[0]["meanings"][0]["definitions"][0]["definition"],
on_error={404: lambda v: f'(no definition for "{v["word"]}")'},
concurrency=5,
depends_on=[first_word],
)
t0 = time.perf_counter()
results = asyncio.run(Graph(define, workers=20).run())
print(f"{len(results)} comics in {time.perf_counter() - t0:.2f}s\n")
results.sort(key=lambda r: r.provenance[1]["value"]["id"] or 0)
for r in results:
comic = r.provenance[1]["value"]
print(f"#{comic['id']:>4} \"{comic['title']}\"")
print(f" {r.value}\n")
20 comics in 0.32s
#2630 "Shuttle Skeleton"
The part of a loom that carries the woof back and forth between the warp threads.
#2631 "Exercise Progression"
Any activity designed to develop or hone a skill or ability.
#2632 "Greatest Scientist"
Relatively large in scale, size, extent, number (i.e. having many parts or members) or duration (i.e. relatively long); very big.
#2633 "Astronomer Hotline"
One who studies astronomy, the stars or the physical universe; a scientist whose area of research is astronomy or astrophysics
#2634 "Red Line Through HTTPS"
Any of a range of colours having the longest wavelengths, 670 nm, of the visible spectrum; a primary additive colour for transmitted light: the colour obtained by subtracting green and blue from white light using magenta and yellow filters; the colour of blood, ripe strawberries, etc.
#2635 "Superintelligent AIs"
(no definition for "superintelligent")
#2636 "What If? 2 Countdown"
(Singlish) Used to contradict an underlying assumption held by the interlocutor.
#2637 "Roman Numerals"
One of the main three types used for the Latin alphabet (the others being italics and blackletter), in which the ascenders are mostly straight.
#2638 "Extended NFPA Hazard Diamond"
To increase in extent.
#2639 "Periodic Table Changes"
Relative to a period or periods.
#2640 "The Universe by Scientific Field"
With a comparative or with more and a verb phrase, establishes a correlation with one or more other such comparatives.
#2641 "Mouse Turbines"
Any small rodent of the genus Mus.
#2642 "Meta-Alternating Current"
(no definition for "meta-alternating")
#2643 "Cosmologist Gift"
(no definition for "cosmologist")
#2644 "fMRI Billboard"
(no definition for "fmri")
#2645 "The Best Camera"
With a comparative or with more and a verb phrase, establishes a correlation with one or more other such comparatives.
#2646 "Minkowski Space"
(no definition for "minkowski")
#2647 "Capri Suns"
(no definition for "capri")
#2648 "Chemicals"
Any specific chemical element or chemical compound or alloy.
#2649 "Physics Cost-Saving Tips"
A medicine or drug, especially a cathartic or purgative.
Every result carries a provenance chain back to the source:
results[0].provenance
# [{"node": "source", "value": {"id": "2630"}},
# {"node": "xkcd", "value": {"id": 2630, "title": "Voting Software"}},
# {"node": "word", "value": {"word": "voting", ...}},
# {"node": "dictionary", "value": "the action of voting"}]
Documentation
| Document | Contents |
|---|---|
| Concepts | Mental model: nodes, results, fan-out, fan-in, workers, execution order |
| Nodes | Source, HTTP, Transform, and custom node reference |
| Graph | Topology discovery, the workers parameter, execution model |
| I/O Mapping | How values flow between nodes, key conflicts, explicit renaming |
| Provenance | The Result class and reading provenance chains |
| Examples | Five complete worked examples |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file specialweek-0.1.0.tar.gz.
File metadata
- Download URL: specialweek-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57be25946252e14651122e9ac6071ce9075f225f4dc37e8d946858bc68378b04
|
|
| MD5 |
d1b8773c8a5eb19ddf75faff4ca16ece
|
|
| BLAKE2b-256 |
23d76ffa6cb899ce50dc55e78c83ed90b1a1a702ea89df6c9db6cd76dc3e5e7a
|
File details
Details for the file specialweek-0.1.0-py3-none-any.whl.
File metadata
- Download URL: specialweek-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca3c5270747df2c4158775c9b7e72d0679756b2253be690a0e37828dbccedba
|
|
| MD5 |
0d43e2e88df292f66ee671514c98bbd1
|
|
| BLAKE2b-256 |
b0a4cd6b9ea6e265a6106ceef2212082e06525a3019db9b565c54199c8cecbf7
|