Polyglot PMD
polyglot-pmd is a reusable Python implementation of the PMD 0.1 polyglot
Markdown notebook specification in spec.md. It parses and validates
plain-text .pmd documents, resolves their dependency graph, runs every cell in
an isolated process, and renders a self-contained HTML report.
PMD cells execute arbitrary code with the privileges of the user running
pmd. Review a document before running, testing, or rendering it.
Install
From this checkout:
python -m pip install -e ./pmd-impl
pmd check pmd-impl/example.pmd --graph
pmd run pmd-impl/example.pmd --fresh
pmd test pmd-impl/example.pmd
pmd render pmd-impl/example.pmd --to html
Once published:
python -m pip install polyglot-pmd
Python 3.10 or newer is required. The package depends only on PyYAML and markdown-it-py. Language interpreters used by a document must also be installed.
Library API
from pathlib import Path
from pmd_notebook import Runner, load, render_html, validate
document = load("analysis.pmd")
errors = validate(document)
if errors:
raise ValueError("\n".join(errors))
result = Runner().run(document, fresh=True)
if not result.ok:
failed = [cell for cell in result.cells if cell.status == "failed"]
page, render_result = render_html(document, result)
Path("analysis.html").write_text(page, encoding="utf-8")
The public API exports parse, load, validate, closure,
topological_order, graph_lines, Runner, Cache, execute, and
render_html, plus the corresponding result dataclasses.
Context Bindings
Each cell receives PMD_CELL_OUT and PMD_CTX_FILE. Built-in engines add these
bindings:
| Engine | Read | Write | Presence check |
|---|---|---|---|
| Python | ctx.get("key") or ctx.key |
ctx.set("key", value) or ctx.key = value |
ctx.has("key") |
| Bash/sh | ctx_get key |
ctx_set key 'JSON_VALUE' |
ctx_has key |
| PowerShell | Get-CtxValue key |
Set-CtxValue key $value |
Test-CtxValue key |
| SQL | ctx_get('key') |
ctx_set('key', 'JSON_VALUE') |
not provided |
Shell reads print JSON, so a stored string includes JSON quotes. SQL uses an
isolated in-memory SQLite database. Override commands under frontmatter
engines.<language>.command; custom engines still receive the two environment
variables but must provide their own context helpers.
Write .png, .jpg, .jpeg, .svg, .csv, .md, or any other attachment
under PMD_CELL_OUT. The HTML renderer embeds all files and makes no network
requests. Python also receives display.markdown, display.csv,
display.image, and display.file convenience methods.
Caching
Successful dependency results are cached under PMD_CACHE_DIR, or
~/.cache/polyglot-pmd by default. Keys include source, attributes, engine
command, and the resolved transitive context. --fresh bypasses reads. A cell
named by --cell always executes; only its dependencies may come from cache.
Context itself remains scoped to one invocation.
Optional Workbench
Run python server.py and open http://localhost:8765. The local workbench is
not installed as part of the Python package.
Publishing to PyPI
- Replace package author metadata if desired and choose the final project URL.
- Run
python -m pip install -e ".[dev]". - Run
pytestandpython -m build. - Check artifacts with
python -m twine check dist/*. - Upload to TestPyPI, install-test the wheel, then upload to PyPI.
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*
PDF and .ipynb are optional PMD render targets and are intentionally not
implemented. The CLI refuses them clearly instead of silently losing content.
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 polyglot_pmd-0.1.0.tar.gz.
File metadata
- Download URL: polyglot_pmd-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
974b0130128eb6c1ed99929dd943374b655817dcbf287b38226b43eb9ea3f020
|
|
| MD5 |
ccd2ec0453cec73ab66fc227fa9bbd80
|
|
| BLAKE2b-256 |
94e86d72719103da498f87cef71354e742c06354d40af143e0e2c525129ec80b
|
File details
Details for the file polyglot_pmd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: polyglot_pmd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c6dd32f918e9f45373995d1e6fac64611d59c402faafb1692a745cb6763cc31
|
|
| MD5 |
cf0eddcb35696502b97792efb246475f
|
|
| BLAKE2b-256 |
e337253f8801708ece9af32fe6006de415078c433ce048a9bfdbc7619f5e23d4
|