markdown-script
Native Python bindings for MDS (Markdown Script) —
a composable LLM prompt-template compiler. Compile .mds templates to Markdown or
structured chat messages in-process, backed by the same Rust core as the MDS CLI and
the Node.js / WASM bindings. Output is byte-identical across every binding.
pip install markdown-script
Not yet on PyPI — the
markdown-scriptname registration and PyPI publishing are tracked in #292 (rename + registration) and #132 (wheel matrix + PyPI publishing pipeline). For now, build from source:pip install ./crates/mds-python(ormaturin build -m crates/mds-python/Cargo.tomlto produce a wheel), with a Rust toolchain andpython3onPATH. Once published, wheels ship ascp311-abi3(CPython 3.11+, one wheel per platform).
Quick start
import markdown_script
# Markdown template
r = markdown_script.compile("Hello {{name}}!", vars={"name": "Alice"})
assert r.kind == "markdown"
assert r.output == "Hello Alice!"
# @message template → structured messages
r = markdown_script.compile("@message user:\nHi\n@end\n")
assert r.kind == "messages"
assert r.messages[0].role == "user"
assert r.output is None # inactive payload is None
# Validate without rendering
markdown_script.check("Hello {{name}}!", vars={"name": "Bob"})
# Compile a file (dependencies come back as absolute paths)
r = markdown_script.compile_file("prompts/agent.mds")
print(r.dependencies)
API
All compile/check functions return a typed, picklable result. Keyword arguments are
keyword-only; scan_imports takes its argument positionally.
| Function | Signature |
|---|---|
compile |
compile(source, *, vars=None, base_path=None, source_map=False, sources_content=False) -> CompileResult |
compile_file |
compile_file(path, *, vars=None, source_map=False, sources_content=False) -> CompileResult |
compile_virtual |
compile_virtual(modules, entry, *, vars=None, source_map=False, sources_content=False) -> CompileResult |
check |
check(source, *, vars=None, base_path=None) -> CheckResult |
check_file |
check_file(path, *, vars=None) -> CheckResult |
check_virtual |
check_virtual(modules, entry, *, vars=None) -> CheckResult |
scan_imports |
scan_imports(source, /) -> list[str] |
lint |
lint(source, *, vars=None, base_path=None, rules=None) -> LintResult |
lint_file |
lint_file(path, *, vars=None, rules=None) -> LintResult |
lint_virtual |
lint_virtual(modules, entry, *, vars=None, rules=None) -> LintResult |
path/base_pathacceptstroros.PathLike.varsis a mapping of string keys to JSON-compatible values; a non-mapping raisesMdsError(code="mds::invalid_options").compile_virtual/check_virtual/lint_virtualresolve imports against an in-memory map;entrymust be a key inmodules.source_map=Truegenerates a Source Map v3 document;result.source_mapis adict. For string-source compilessources[0]is"input.mds".sources_content=Trueembeds the original source text insourcesContent[](requiressource_map=True). ⚠ Privacy:sources_content=Trueembeds the full template source in the map.rulesis a mapping of rule name → severity string ("off","info","warn","error"). Unknown severity values raiseMdsError(code="mds::invalid_options"); unknown rule names emit a warning and lint continues — the unknown name has no effect, but a non-emptyresult.lint_warningslist signals the problem so callers can surface it.LintResultexposes.version,.truncated,.lint_warnings,.to_dict(),.to_json(), and.files— alist[LintFileReport]. EachLintFileReporthas.file(str) and.diagnostics(list[LintDiagnostic]).LintDiagnosticcarries.rule,.severity,.message,.help(str | None),.fixable(bool),.fix_edits(list[dict] | None), and.span(Span | None).LintFileReportandLintDiagnosticare frozen, picklable, and comparable by value.files[].filekey:lint()sets this to"input.mds"(string-source);lint_file()sets it to the file's path;lint_virtual()sets it to the caller-supplied entry key. The CLI additionally relabels stdin input as"<stdin>"— this asymmetry does not apply to the Python binding.
Result objects
CompileResult exposes .kind ("markdown" | "messages"), .output (str | None),
.messages (list[Message] | None), .warnings, .dependencies, and .source_map
(dict | None). CheckResult exposes .warnings. Both offer .to_dict() and .to_json().
to_dict()vsto_json()asymmetry (source maps):CompileResult.to_dict()always includes"sourceMap": Nonewhen no source map was generated — Python-idiomatic always-present.to_json()omits the key when absent, matching the canonical wire format shared with the CLI, napi, and WASM surfaces for byte-identical cross-surface parity.
Results are frozen, comparable by value, intentionally unhashable, and picklable.
Errors
Every failure raises markdown_script.MdsError (a subclass of Exception):
try:
markdown_script.compile("Hello {{undefined}}!")
except markdown_script.MdsError as e:
print(e.code) # "mds::undefined_var"
print(str(e)) # == e.message
print(e.help) # hint, or None
if e.span:
print(e.span.line, e.span.column) # 1-indexed
Concurrency
Compilation is synchronous, stateless CPU work and releases the GIL, so calls
parallelise across threads. For asyncio, offload with asyncio.to_thread(markdown_script.compile, src).
The extension is also free-threading (cp314t) ready — result classes are frozen and
the module declares gil_used = false — though a free-threaded wheel is not yet shipped.
License
MIT © the MDS authors.
Release files for markdown-script 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| markdown_script-0.4.2.tar.gz | 508.1 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| markdown_script-0.4.2-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| markdown_script-0.4.2-cp311-abi3-musllinux_1_2_x86_64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ x86-64 | Details |
| markdown_script-0.4.2-cp311-abi3-musllinux_1_2_aarch64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ ARM64 | Details |
| markdown_script-0.4.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| markdown_script-0.4.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| markdown_script-0.4.2-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| markdown_script-0.4.2-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size:5.9 MB
Release files / markdown_script-0.4.2.tar.gz
| Download URL | markdown_script-0.4.2.tar.gz |
|---|---|
| Size | 508.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be55877feb8b5d81f2dfde902e778d574bb180ceda52b8b31df5f85ac490edd9
|
|
BLAKE2b-256 checksum How to use checksums |
c997caee7d0fbcbf0353ed1b04037aa8db9f21450ea1a30c9b7c0af1c1bd93b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-win_amd64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 685.2 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a0df3ab8c2aa51e562e066f996875514c6ca3c0c818d0609930235007ed98c28
|
|
BLAKE2b-256 checksum How to use checksums |
dfe7e7eced5584b78286f35b0cca63683617d8690d5cd1e276e2363ae364265d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 964.2 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ca91f271f6e097d91882b744eb55a59b9b2a658a05877d2ca34b3bb4a5b91fff
|
|
BLAKE2b-256 checksum How to use checksums |
fc5ae04a8ff4d874cc45ef9ed6e2289614676e660639f6dd20a474e7b80e02d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-musllinux_1_2_aarch64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 893.8 kB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2d9d6d418e57049f52a6e31b8db089f6a51f6674f8dee2925dceb4976c3957bb
|
|
BLAKE2b-256 checksum How to use checksums |
2ac0997fd34b54efc9b41bd42af0abca5eb8edb84919843b6477b3f9786b3a2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 750.6 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
88077cc843d5ce984741e59cadbdb0d81a4f5652296377da6cf0f4ea1b3ee7c4
|
|
BLAKE2b-256 checksum How to use checksums |
5efbcb9aefcbb2a1b659266a3ee20222be5bf6ee0357d5c32c98e24f3705b404
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 715.1 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
62dc02f600671c77f2e1882d9cfdb45d3a47c6562ca936699b1894a2773631df
|
|
BLAKE2b-256 checksum How to use checksums |
14c85c80b3fb619ada6ed5a4b9904fc911ff6ae863778e59c0dd08cb9748917e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 685.0 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f37f1c002373d248ec45fa07a262c22f0364255a6a43a5c7dcca329e9f4bcebd
|
|
BLAKE2b-256 checksum How to use checksums |
75f5ac52d7e4fec4231ffa67e833ee82bef423327cab39bb29b21bda4598c841
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / markdown_script-0.4.2-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | markdown_script-0.4.2-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 711.6 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
7a260fda45fa5de0b6e71c8c2119c51546524c4dcb40d089eb8dfbc823812de9
|
|
BLAKE2b-256 checksum How to use checksums |
de29cf2e054392c78a1a12c9771f5e4e0309b3e0985d6595ca1e0fd84983d74c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency log