Read-only mirror of https://github.com/openZH/starter-code-openzh-generator — Kanton Zürich. Issues & pull requests at the source.
  • Python 84.1%
  • Jupyter Notebook 10%
  • R 4.9%
  • Makefile 1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-22 14:58:06 +01:00
.github fix(ci): synchronize lockfile with dependency settings 2026-11-15 20:46:41 +01:00
_templates docs: align documentation with current generator 2026-11-15 20:05:26 +01:00
_work Initial commit 2026-09-28 09:47:50 +02:00
src/starter_code_openzh_generator fix: validate resource mappings and handle missing distributions, remove eMudhra sec fix 2026-11-15 20:42:42 +01:00
tests fix: validate resource mappings and handle missing distributions, remove eMudhra sec fix 2026-11-15 20:42:42 +01:00
.gitattributes Initial commit 2026-09-28 09:47:50 +02:00
.gitignore docs: align documentation with current generator 2026-11-15 20:05:26 +01:00
.python-version Initial commit 2026-09-28 09:47:50 +02:00
_.code-workspace Initial commit 2026-09-28 09:47:50 +02:00
AGENTS.md fix(security): update CA bundles after emSign incident 2026-10-26 10:42:33 +01:00
config.yaml Initial commit 2026-09-28 09:47:50 +02:00
LICENSE Initial commit 2026-09-28 09:47:50 +02:00
Makefile Initial commit 2026-09-28 09:47:50 +02:00
NOTES.md docs: remove eMudhra note 2026-11-15 21:11:44 +01:00
PLAN.md fix: validate resource mappings and handle missing distributions, remove eMudhra sec fix 2026-11-15 20:42:42 +01:00
pyproject.toml fix: validate resource mappings and handle missing distributions, remove eMudhra sec fix 2026-11-15 20:42:42 +01:00
README.md docs: clarify PAT token settings and troubleshooting 2026-11-22 14:58:06 +01:00
uv.lock fix(ci): synchronize lockfile with dependency settings 2026-11-15 20:46:41 +01:00

Starter Code Generator OpenZH

Generate Python notebooks and R Markdown files for CSV resources in the Canton of Zurich's open-data catalogue. Each file loads one resource and provides basic summaries and plots to help users start exploring the data.

Looking for notebooks to use? Browse openZH/starter-code-openZH. This repository maintains the generator behind them.

How it works

The generator reads the catalogue metadata, selects resources listed as CSV, and fills the templates in _templates/. It writes notebooks and an overview with Colab, Python and R links to _work/. Data is downloaded when a notebook runs.

Python notebooks can run in Colab or a local notebook environment; R Markdown files need a local R environment with the packages used by the template. Check the inferred CSV separator and column types before using the data for analysis.

Run locally

With uv installed, run from the repository root. The generator requires Python 3.13 or newer; the checkout and CI use Python 3.13.

uv sync --locked
uv run updater
uv run updater --verify-output

The Python package is starter_code_openzh_generator; uv run python -m starter_code_openzh_generator also runs the generator. The updater command remains available.

Find the generated files in _work/02_python/ and _work/01_r-markdown/, and browse them through _work/README.md. The final command checks the generated output without downloading metadata or executing notebooks. Local runs do not publish anything.

Generated notebook directories are rebuilt on every run. Keep hand-written files outside them, and run only one generator per output directory at a time.

Generation stages and verifies the output before replacing it, preserving files outside the notebook directories except the generated README.md, index.md and manifest.json. If replacement or rollback is interrupted, a sibling ._work.previous backup may remain. Inspect and recover that backup before rerunning; generation refuses to overwrite it. A custom output root uses the backup name .<output-root-name>.previous.

Customize

Edit config.yaml to change catalogue settings, output paths, metadata fields or links to the published repository. Edit the files in _templates/ to change the overview and notebook content, preserving their template markers.

To use a different configuration:

uv run updater --config path/to/config.yaml

The default configuration is config.yaml in the working directory. Relative paths to configuration files, output roots (paths.temp_prefix) and template folders use the working directory, including when using --config. Notebook output subdirectories are relative to the output root; template filenames are relative to the template folder.

Publish automatically

The GitHub Actions workflow generates and publishes notebooks from main on pushes, weekly, or when triggered manually. Quality checks and output verification must pass before publication.

To set up publishing:

  1. Set the target account, repository and branch in both config.yaml and the workflow's publishing step. Keep its source-directory aligned with the configured output root.
  2. Create a fine-grained personal access token with the target organization (openZH by default) as the resource owner. Select the target repository (starter-code-openZH by default) and grant Contents → Read and write. The token owner needs write access to the target repository, and the organization may require token approval. If you use a classic token, grant repository write access and authorize it for the organization if it uses SAML SSO. GitHub token guide
  3. In the generator repository, go to Settings → Secrets and variables → Actions and save the token as the repository secret PAT. The workflow passes it to the publishing action as API_TOKEN_GITHUB.
  4. Use a target repository dedicated to generated output and review _work/LICENSE.md before publishing. Enable GitHub Pages in the target repository and deploy from the target branch's root. The generated index.md serves as the entry page.

Troubleshoot publishing authentication

If the push reports Invalid username or token, check the publishing step's log. A masked API_TOKEN_GITHUB: *** shows that the action received a value. Check whether the token expired, was revoked, or lost access to the target repository. Update the PAT secret if the token value changed, then select Re-run failed jobs. Verify that the generated commit lands on the target branch. A run that reports Everything up-to-date had no changes to publish.

Development

After uv sync --locked, run make check for formatting, lint and tests. Run make help for other commands. Automated checks do not execute R notebooks; test R template changes in an R environment.

Ideas and contributions are welcome through issues and pull requests.

This project is inspired by and based on the work of Alexander, Philipp, Stefan, Adrian, Laure, and Patrick.

Thanks to our colleagues at Stadt Zürich, who have substantially expanded on the original ideas with their advanced starter-code project!

Related projects include starter notebooks for opendata.swiss and the OGD Thurgau starter code generator.