Parameterise a Quarto document for the Jupyter Engine
Project description
qparameterize
Parameterize Quarto documents for batch rendering with multiple parameter sets for the jupyter engine.
However, when rendering to HTML with Quarto's Jupyter engine, each execution overwrites output files (figures, cell outputs) because filenames like cell-output-1 are only unique within a single file, not across parameterized runs.
This tool solves that by generating separate .qmd files with unique labels, so Quarto can render them all without conflicts.
Why an alternative to quarto's default parameterizing?
The default is excellent for parameterizing Jupyter notebooks when generating single-file outputs e.g. notebooks, PDFs or contained HTML pages.
See Quarto documentation on parameters for more context.
The Jupyter engine generates output filenames with prefixes like cell-output-1, cell-output-2 for figures and other artifacts.
These prefixes are the automatic labels of the cells.
Even when cells are labelled, those labels are only unique within the file.
When you render multiple parameterized versions, the last run overwrites all previous outputs.
e.g. If you render a file map.qmd with parameters to html
quarto render map.qmd -P country:afghanistan -o afghanistan.html
...
quarto render map.qmd -P country:zimbabwe -o zimbabwe.html
The artifacts for all renderings will be stored in _site/map/.
If the first cell of map.qmd has an image output it will be saved as _site/map/figure-html/cell-output-1.png for all the renderings.
All the HTML files will show display images from the last rendering!
Solution
This package addresses the issue by:
- Substituting parameter values in the parameters block
- Adding unique labels to all code blocks based on parameter values
- Outputs a parameterized
qmdfile
With this approach, the parameterizing is separated from the rendering.
When rendering, Quarto will know of all the qmd source files.
Workflow
- Create a
.qmdwith a parameters block - Run
qparameterizefor each parameter set → generatesinput--param-values.qmd - Run
quarto renderon all generated files
Installation
Requires Python 3.11+.
# With uv
uv pip install qparameterize
# With pip
pip install qparameterize
Usage
Define a parameters block
In your .qmd file, mark a code block with the parameters tag:
```{python}
#| tags: [parameters]
animal = "cat"
count = 5
```
Run the tool
# Using key:value pairs
uv run qparameterize input.qmd -P animal:dog -P count:10
# Using a YAML file
uv run qparameterize input.qmd --execute-params params.yaml
# With custom output filename
uv run qparameterize input.qmd -P animal:dog -P count:10 -o ten-dogs.qmd
Example YAML params file
animal: dog
count: 10
Output
A new file with parameter values in the filename:
input.qmd → input--dog-10.qmd
The output file has:
- Substituted parameter values
- Unique labels on all code blocks (e.g.,
#| label: dog-10--1)
Cleaning up
To delete all previously generated files:
uv run qparameterize --clean
The generated files are tracked in .quarto/qparameterize.txt.
In A Quarto Project
Parameterize in the pre-render step and clean up in the post-render.
project:
type: website
pre-render:
- uv run qparameterize input.qmd -P animal:dog -P count:10
- uv run qparameterize input.qmd -P animal:elephant -P count:7
post-render:
- uv run qparameterize --clean
Development
# Lint
uv run --group dev ruff check src/
# Test
uv run --group dev pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qparameterize-0.1.1.tar.gz.
File metadata
- Download URL: qparameterize-0.1.1.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92b182b8a1017073b53c73dbd6345f3a628dbdecde713d143b9e2336993788ac
|
|
| MD5 |
a54f482cb76f801d0a2236df0fbb5153
|
|
| BLAKE2b-256 |
3e0c22c130b3ccec74b6a3c70ac2ee040504b07c62307dcd7c28b532ac95d961
|
Provenance
The following attestation bundles were made for qparameterize-0.1.1.tar.gz:
Publisher:
release.yml on has2k1/qparameterize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qparameterize-0.1.1.tar.gz -
Subject digest:
92b182b8a1017073b53c73dbd6345f3a628dbdecde713d143b9e2336993788ac - Sigstore transparency entry: 816476438
- Sigstore integration time:
-
Permalink:
has2k1/qparameterize@e3b2993c6758dcfeb9b3c17c1500d025da6cc943 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/has2k1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3b2993c6758dcfeb9b3c17c1500d025da6cc943 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qparameterize-0.1.1-py3-none-any.whl.
File metadata
- Download URL: qparameterize-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a263a1468fdfec8f8fa0edfa953ea1f059c957772ca4c33215ca2640c2f11c7d
|
|
| MD5 |
c80e4a5cfe1741e06d07494b2c4e043e
|
|
| BLAKE2b-256 |
8d83bd6d68cf336581c07c14de11ba51a2daecb8fe725e221550f2d8e4cc09e8
|
Provenance
The following attestation bundles were made for qparameterize-0.1.1-py3-none-any.whl:
Publisher:
release.yml on has2k1/qparameterize
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qparameterize-0.1.1-py3-none-any.whl -
Subject digest:
a263a1468fdfec8f8fa0edfa953ea1f059c957772ca4c33215ca2640c2f11c7d - Sigstore transparency entry: 816476503
- Sigstore integration time:
-
Permalink:
has2k1/qparameterize@e3b2993c6758dcfeb9b3c17c1500d025da6cc943 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/has2k1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e3b2993c6758dcfeb9b3c17c1500d025da6cc943 -
Trigger Event:
push
-
Statement type: