Project scripts
Anything that works with the whole project goes in scripts/: an audit, a report, a custom export, a bulk operation. A script is a Python file with a run(project, ...) function. What it does is up to you.
"""Write a Markdown data dictionary: every model, its grain, and its columns."""
def run(project, layer: str = "", output: str = "target/data_dictionary.md"): models = project.models(layer=layer or None) lines = ["# Data dictionary", ""] for model in models: lines += [f"## {model.name}", ""] lines += [f"| {name} | {kind} |" for name, kind in model.columns.items()] target = project.root / output target.parent.mkdir(parents=True, exist_ok=True) target.write_text("\n".join(lines), encoding="utf-8") print(f"Wrote {output}: {len(models)} models")selectjoin run data_dictionary --layer martsWrote target/data_dictionary.md: 1 modelsSelectJoin loads and validates the project first, then calls run with it. The layers template includes a fuller version of this script, with descriptions and grains.
List and create
Section titled “List and create”selectjoin scriptsSCRIPT OPTIONS DESCRIPTIONchecks - Data checks, not a script. List them with: selectjoin checksdata_dictionary --layer --output Write a Markdown data dictionary: every model, its grain, and its columns.The description is the first line of the file’s docstring. Listing reads the files; it does not run them. selectjoin scripts --json returns the same, with each option’s type and default.
selectjoin scripts --new audits.nullsThis writes scripts/audits/nulls.py with a small run function to start from.
Parameters become options
Section titled “Parameters become options”The parameters after project are the script’s command-line options.
| In the function | On the command line |
|---|---|
limit: int = 20 |
--limit 50, converted to an integer |
dry_run: bool = False |
--dry-run or --no-dry-run |
names: list[str] = () |
--names orders customers |
since: str (no default) |
--since 2026-01-01, required |
**options |
any other --name value pair, as text |
selectjoin run NAME --help prints the options one script takes.
Organizing scripts
Section titled “Organizing scripts”- Folders group scripts:
scripts/audits/nulls.pyis run asaudits.nulls. - Files and folders whose names start with
_are skipped, so helpers can live beside scripts. - A script can import the project’s components:
from ..components.orders import clean_orders. - If
runreturns an integer, it becomes the command’s exit code. That lets a script fail a CI job. - An error inside a script is reported with the script’s file and line.
What scripts are not
Section titled “What scripts are not”Scripts use the project; they do not add models to it. Models live in models/.
One file in the folder is different. scripts/checks.py holds the project’s data checks: it defines build(project) instead of run, and SelectJoin lists and compiles what it yields with selectjoin checks and selectjoin compile-checks. selectjoin scripts shows it marked as checks, and selectjoin run checks explains which command to use instead. To build a whole project in code with no model files, see Scripting without files.
A script is ordinary Python and can do anything Python can. Read a script before running it in a project you did not write.