Quick Start¶
This guide builds and runs a two-stage pipeline.
Mental Model¶
Think artifact-first, not stage-first. A stage is a function from data to data; calling one stage with the result of another is what creates the dependency:
- Wrong: "Stage A triggers Stage B"
- Right: "This file changed. What needs to happen because of that?"
Invalidation is content-addressed: same inputs + same code + same parameters = same outputs.
1. Initialize the Project¶
Pivot projects live in a git repository:
pivot init creates:
.pivot/: the project marker and itsconfig.yaml<state dir>/.gitignore: keeps the cache, state database, artifact locks and agent socket out of git;<state dir>iscore.state_dirand defaults to.pivot.pivotignore: files a directory input's hash leaves out, such as__pycache__/and*.pyc, so a change to them reruns nothing; watch mode skips them too (see Directory inputs and.pivotignore)
core.state_dir selects where Pivot writes state. Commit the lock files under
<state dir>/stages/; they record what ran and what it produced.
2. Add Input Data¶
Raw inputs live under data/raw/:
3. Create the Pipeline¶
Create pipeline.py:
# pipeline.py
import pandas as pd
from pivot import Pipeline, StageParams, stage
class CleanParams(StageParams):
min_value: float = 0.0
@stage
def clean(records: pd.DataFrame, params: CleanParams) -> pd.DataFrame:
"""Remove rows with missing values and values below the threshold."""
cleaned = records.dropna()
return cleaned[cleaned["value"] >= params.min_value]
@stage
def summarize(rows: pd.DataFrame) -> dict:
"""Compute summary statistics."""
values = rows["value"]
return {
"count": len(values),
"mean": float(values.mean()),
"min": float(values.min()),
"max": float(values.max()),
}
with Pipeline("quickstart") as pipeline:
records = pipeline.input("records.csv")
cleaned = clean(records, params=CleanParams(min_value=0.0))
summarize(cleaned)
What each part does:
@stagemarks a function as a stage. Outside a pipeline block it is an ordinary function you can call in tests.CleanParamsis the stage's configuration, a Pydantic model. Each stage that needs configuration gets its ownStageParamssubclass.pipeline.input("records.csv")declares the raw inputdata/raw/records.csv. Its.csvextension tells Pivot to load it as a DataFrame.clean(records, ...)inside thewithblock does not runclean. It records a stage and returns a handle to its output; passing that handle tosummarizemakessummarizedepend onclean.- The return type chooses the file format: a
DataFrameis saved as JSON Lines, adictas YAML.
4. Run the Pipeline¶
Pivot will:
- Find
pipeline.pyand run it to build the DAG - Run
quickstart/clean, thenquickstart/summarize - Write
data/quickstart/clean.jsonlanddata/quickstart/summarize.yaml - Record each stage's code, parameters and input hashes in
<state dir>/stages/quickstart/
5. Re-run (Cached)¶
Nothing changed, so both stages are reported as cached and nothing executes.
6. Change Code and Re-run¶
Edit summarize in pipeline.py to also report the total:
@stage
def summarize(rows: pd.DataFrame) -> dict:
"""Compute summary statistics."""
values = rows["value"]
return {
"count": len(values),
"mean": float(values.mean()),
"min": float(values.min()),
"max": float(values.max()),
"total": float(values.sum()),
}
pivot status reports quickstart/summarize as stale ("Code changed"); clean stays cached. pivot repro runs only summarize.
7. Change a Parameter¶
Parameters can be overridden per stage in params.yaml without touching code:
The explanation shows the parameter change for quickstart/clean and marks summarize as stale because clean will produce different output bytes. Run pivot repro to apply it, or delete params.yaml to return to the values in code.
Next Steps¶
- Artifacts & the DAG: how handles form the graph
- Pipelines: inputs, variants, and multiple pipelines
- Outputs: multi-output stages, metrics, and plots
- Watch Mode: re-run automatically as you edit