Skip to content

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.

scripts/data_dictionary.py
"""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")
Terminal window
selectjoin run data_dictionary --layer marts
Wrote target/data_dictionary.md: 1 models

SelectJoin 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.

Terminal window
selectjoin scripts
SCRIPT OPTIONS DESCRIPTION
checks - Data checks, not a script. List them with: selectjoin checks
data_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.

Terminal window
selectjoin scripts --new audits.nulls

This writes scripts/audits/nulls.py with a small run function to start from.

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.

  • Folders group scripts: scripts/audits/nulls.py is run as audits.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 run returns 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.

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.