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.
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.htmlThe 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!
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.
- Create a
.qmdwith a parameters block - Run
qparameterizefor each parameter set → generatesinput--param-values.qmd - Run
quarto renderon all generated files
Requires Python 3.11+.
# With uv
uv pip install qparameterize
# With pip
pip install qparameterizeIn your .qmd file, mark a code block with the parameters tag:
```{python}
#| tags: [parameters]
animal = "cat"
count = 5
```# 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.qmdanimal: dog
count: 10A 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)
To delete all previously generated files:
uv run qparameterize --cleanThe generated files are tracked in .quarto/qparameterize.txt.
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# Lint
uv run --group dev ruff check src/
# Test
uv run --group dev pytest