Reactive Python execution engine for Typst documents
Project description
typst_pyexec
typst_pyexec is a reactive Python execution engine for Typst documents.
It executes Python fences inside .typ files, captures outputs (stdout, figures, tables), and injects rendered Typst markup into an intermediate file (*.typst_pyexec.typ) that can be compiled directly.
Core Capabilities
- Reactive dependency graph based on Python AST analysis
- Incremental execution with source-hash cache
- Persistent Jupyter kernel between builds
- Automatic cold-kernel hydration for dependency prerequisites
- Matplotlib figure export to SVG with PNG fallback
- Subfigure reconstruction via
figure(grid(...)) - DataFrame HTML rendering to Typst
#table(...) - Watch mode with automatic rebuilds
Installation
pip install typst_pyexec
For development:
uv sync --extra dev
CLI Usage
Build once:
typst_pyexec build document.typ
Watch and rebuild on save:
typst_pyexec watch document.typ
Clean local state directory:
typst_pyexec clean
Common options:
--output-dir <dir>: write intermediate/state outputs to a custom folder--no-cache: disable cache lookups and force execution--jobs <n>: reserved for future multi-kernel scheduling (-1default)--compiler <cmd>: Typst compiler binary name/path (defaulttypst)
Block Options (%|)
Place options at the top of a Python fence:
```python
%| echo: false
%| raw: true
%| figure: true
print("hello")
```
Supported options:
execute(defaulttrue): skip execution whenfalserefresh(defaultfalse): force this cell to run every buildecho(defaulttrue): show or hide source coderaw(defaulttrue): show or hide textual runtime output (stdout, traceback,text/plaindisplay bundles)figure(defaulttrue): show or hide rendered figurescaption: explicit figure caption overridelabel: Typst label for cross-referenceskeep-subplots(defaultfalse): preserve multi-axis plot as one imageimg-*: passthrough kwargs for Typstimage(...)fig-*: passthrough kwargs for Typstfigure(...)grid-*: passthrough kwargs for Typstgrid(...)
Behavior notes:
cell_idis internal and generated automatically.- Option-only edits do not invalidate cache because cache keys are based on Python source.
- To re-run on option updates, set
refresh: true.
Figure and Caption Behavior
- For single-axis plots, title text is promoted into Typst caption when
captionis not set. - For subplot grids, each axis title becomes child caption; suptitle becomes outer caption.
- Title text is removed from exported images after promotion to captions.
- If SVG export fails and PNG is emitted, renderer auto-resolves PNG paths in final Typst output.
How It Works
- Parse Python fences from Typst source
- Build def/use DAG from AST
- Compute changed cells from source-hash cache
- Execute required cells in topological groups
- Capture stdout, display bundles, and figure artifacts
- Render Typst fragments per cell
- Inject into
document.typst_pyexec.typ - Compile with Typst compiler
Local State
typst_pyexec writes runtime state into .typst_pyexec/:
kernel_connection.json: reconnect data for persistent kernelcache/: JSON entries keyed by SHA-256 of cell sourcefigures/: SVG/PNG artifactsnotebook.ipynb: synchronized notebook representation
Development Quality Gates
Run checks locally:
uv run ruff check .
uv run black --check typst_pyexec tests
uv run mypy typst_pyexec
uv run pytest
CI/CD (GitHub Actions)
CI: matrix on Ubuntu and Windows, Python 3.10-3.12, with lint + format + type-check + tests + coverage artifactRelease: tag-driven (v*.*.*) build and publish workflow for PyPI using trusted publishing
Workflows are in:
.github/workflows/ci.yml.github/workflows/release.yml
Publish to PyPI
typst_pyexec is already configured for trusted publishing through GitHub Actions.
Release steps:
- Bump version in
pyproject.tomlandtypst_pyexec/__init__.py. - Commit and push to main.
- Create and push a version tag:
git tag v0.1.1
git push origin v0.1.1
- GitHub Actions runs
.github/workflows/release.ymland publishes to PyPI.
Pre-tag checklist:
python -m pytest -qis green.python -m buildsucceeds.python -m twine check dist/*passes.- Version matches in
pyproject.tomlandtypst_pyexec/__init__.py. - Git tag matches that version (
vX.Y.Z).
Local preflight checks before tagging:
python -m build
python -m twine check dist/*
If you prefer token-based manual publishing:
python -m twine upload dist/*
Use in Other Repositories
After publishing, install as a normal dependency.
With pip:
pip install typst_pyexec
With uv (project dependency):
uv add typst_pyexec
With uvx (run CLI without adding dependency):
uvx typst_pyexec build document.typ
License
MIT
Project details
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 typst_pyexec-0.0.1.tar.gz.
File metadata
- Download URL: typst_pyexec-0.0.1.tar.gz
- Upload date:
- Size: 180.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0dd1b1358800b1d64cb9bcfc0b773f87f0e295f871a1a2ea2559444c8700cd2
|
|
| MD5 |
b7db770ab2d70465bb71ce737322c1dd
|
|
| BLAKE2b-256 |
b6a890dd66a198da2569da9b3b58ff1e9dec779dcf0cbfa0cc7bd015156a95f2
|
Provenance
The following attestation bundles were made for typst_pyexec-0.0.1.tar.gz:
Publisher:
release.yml on Arkanthara/typst_pyexec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typst_pyexec-0.0.1.tar.gz -
Subject digest:
b0dd1b1358800b1d64cb9bcfc0b773f87f0e295f871a1a2ea2559444c8700cd2 - Sigstore transparency entry: 1110059323
- Sigstore integration time:
-
Permalink:
Arkanthara/typst_pyexec@6b328c65d877853882c2243132982091b3115e91 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Arkanthara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b328c65d877853882c2243132982091b3115e91 -
Trigger Event:
push
-
Statement type:
File details
Details for the file typst_pyexec-0.0.1-py3-none-any.whl.
File metadata
- Download URL: typst_pyexec-0.0.1-py3-none-any.whl
- Upload date:
- Size: 32.4 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 |
c006c8c6666e557cae80fa2a7044b30173c4d9ed8a9662dfb42ff49ff1f12b06
|
|
| MD5 |
46ccf778aa879db8d5a4ae4cfefb94fd
|
|
| BLAKE2b-256 |
204089e673f90693303808914ef14beef3f1c7fe1800ad34864ae3ce2b5a65a2
|
Provenance
The following attestation bundles were made for typst_pyexec-0.0.1-py3-none-any.whl:
Publisher:
release.yml on Arkanthara/typst_pyexec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typst_pyexec-0.0.1-py3-none-any.whl -
Subject digest:
c006c8c6666e557cae80fa2a7044b30173c4d9ed8a9662dfb42ff49ff1f12b06 - Sigstore transparency entry: 1110059330
- Sigstore integration time:
-
Permalink:
Arkanthara/typst_pyexec@6b328c65d877853882c2243132982091b3115e91 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Arkanthara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b328c65d877853882c2243132982091b3115e91 -
Trigger Event:
push
-
Statement type: