Substrate
A Python runtime that coordinates concurrent computations through a single append-only log. A topology declares the computations and the conditions that connect them. The log records every output, every lifecycle transition, every decision the runtime made.
pip3 install substrate-kernel
python3 -m substrate install
substrate demo replay code_review
The nine pieces
A topology in Substrate is a function that declares which computations run and what connects them. They are built of nine fundamental ideas.
A Producer takes typed input and yields typed output. The runtime treats it as opaque — it sees the input, the output,and nothing between.
An Event is one typed, immutable record. Producers produce Events.
The Bus is the ordered log of Events. Producers write only to the bus.
A View is any projection of the Bus: a count, a filtered list, or the latest value of some kind.
A Predicate examines the Views and returns yes or no given some condition.
A Trigger watches the Bus and starts a new Producer when its Predicate passes.
A Route subscribes to the Bus much like a View does, but instead of projecting a summary it extracts values and stages them as input for future producers.
A TerminationPolicy decides ending conditions: count events, pause for outside input, or wait for quiescence — the state where no Producers are running and no Triggers can fire.
The run record is the Bus written to disk, checksummed and replayable.
A toy topology
Generator yields items. After three, a Trigger starts Processor with the latest item as input. When no Producers are running and no Triggers can fire, the TerminationPolicy ends the run. The run record captures every Event.
flowchart TD
Gen["<b>Generator</b><br/>Producer"]
Proc["<b>Processor</b><br/>Producer"]
Gen -- "yields item Events" --> Bus
Proc -- "yields result Events" --> Bus
Bus(["<b>Bus</b><br/>append-only log"])
Bus -- "projects into" --> ItemCount["<b>ItemCount</b><br/>View · count of items"]
Bus -- "projects into" --> Latest["<b>LatestItem</b><br/>View · most recent item"]
ItemCount -- "count ≥ 3 ?" --> Pred{"<b>Predicate</b>"}
Pred -- "yes →" --> Trig["<b>StartProcessor</b><br/>Trigger"]
Trig -- "starts" --> Proc
Latest -- "fills slot" --> Route["<b>latest_item</b><br/>Route"]
Route -- "input to" --> Proc
ItemCount -- "read by" --> TP["<b>quiescence()</b><br/>TerminationPolicy"]
Latest -- "read by" --> TP
TP -- "FINALISE_RUN" --> Halt(("halt"))
Bus -. "serialized to disk" .-> RR["<b>run record</b><br/>checksummed JSONL"]
The cycle is the point: Producer → Event → Bus → View → Predicate → Trigger → new Producer. Everything passes through the Bus. Producers share nothing else.
What you can build with them
Each of these is a topology — a short Python program against the runtime:
- An ensemble of several cheap models on the same task, with a stronger model adjudicating and the losing runs cancelled once a verdict lands.
- A pipeline that retries a failed step with the failure reason fed back in, escalates after N attempts, and pauses for a human when it can't recover.
- A code-writing setup where one Producer streams code while a checker Producer reviews it as it arrives — running concurrently with the still-streaming writer.
- A planner that emits subtasks, each starting a solver that can itself emit more subtasks — recursive decomposition to arbitrary depth.
- An adversarial pair — one Producer writes, another attacks — streaming at each other from the start.
- A simulation: many Producers acting each tick against a shared world-state Producer, the whole run replayable from the log.
- A conversation between models as alternating Producers, ended on a convergence condition.
- A tool-using loop as a chain of model → tool → model Producers, each call independently replayable.
Most of these ship as bundled topologies with committed run records — substrate topology list to browse, substrate demo replay <name> to read one back. The tutorial walks from zero to a working topology.
Install
pip3 install substrate-kernel
python3 -m substrate install
substrate demo replay code_review
python3 -m substrate install links the substrate command into ~/.local/bin and, if that folder
is not on PATH, adds it to the shell's startup file; a new terminal then has the command. The import
name is substrate.
From source:
uv venv --python 3.12
uv pip install -e ".[dev]"
scripts/ci_local.sh
Docs
| Doc | What |
|---|---|
| tutorial.md | Start here. Install to a running topology. |
| demo.md | Three topologies annotated against their records. |
| adding-a-topology.md | Package a topology and register it. |
| walkthroughs/ | Worked topologies with real-model transcripts. |
| replay.md | The replay fidelity levels. |
| api.md | The public API surface. |
Layout
src/ is the runtime. docs/ is how to use it. CONTRIBUTING.md is how to develop it. Four specs govern the code:
| Spec | Path |
|---|---|
| Kernel semantics | docs/specs/kernel_spec/v15.md |
| Product | docs/specs/product_spec/draft7.md + addenda |
| Technical | docs/specs/technical_spec/draft5.md + addenda |
| Design | docs/specs/design_spec/draft1.md |
Status
1.0.0 on PyPI as substrate-kernel. Python 3.12+.
Licensing and use
This project is licensed under the PolyForm Noncommercial License 1.0.0. Source-available; noncommercial use only.
Permitted uses include personal, research, educational, hobbyist,
government, and nonprofit charitable use. Commercial use of any kind
is not permitted under this license. See LICENSE for the full text
and the additional statements on AI-mediated derivation that ride
alongside it.
Position on machine learning
The licensor does not consent to the use of this software, its
documentation, or its records as training data for AI or machine
learning systems. Training crawlers should honor the robots.txt and
ai.txt at the repository root or any hosted docs site.
A reimplementation produced by exposing this codebase to an AI or ML system is a derivative work and is subject to the PolyForm Noncommercial License in full — that is, no commercial use of the derivative work.
See LICENSE Sections A and B for the full statement.
Metadata
Release files for substrate-kernel 1.1.2
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 |
|---|---|---|---|---|
| substrate_kernel-1.1.2.tar.gz | 1.5 MB | Without provenance | Details for substrate_kernel-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| substrate_kernel-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for substrate_kernel-1.1.2-py3-none-any.whl |
Total release size: 2.7 MB
Release files / substrate_kernel-1.1.2.tar.gz
| Download URL | substrate_kernel-1.1.2.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72696036435758dd0f49ae48c3cd577d227c150dba7f924966c744eed2091182
|
|
BLAKE2b-256 checksum How to use checksums |
93f8b4f386b004b116d1d19823e226ff47473b78b84b22789d3658f00acba8d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / substrate_kernel-1.1.2-py3-none-any.whl
| Download URL | substrate_kernel-1.1.2-py3-none-any.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ef18c07249a94ead2b778b1c7b2ed63b8f5ec80ae9e7e9ed682c1846b301af0
|
|
BLAKE2b-256 checksum How to use checksums |
e272970ac893c268b938811f7023fc01d0c1d3a519496816709b67bf243c681f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for substrate-kernel 1.1.2
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.