Skip to main content

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-script name 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 (or maturin build -m crates/mds-python/Cargo.toml to produce a wheel), with a Rust toolchain and python3 on PATH. Once published, wheels ship as cp311-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_path accept str or os.PathLike.
  • vars is a mapping of string keys to JSON-compatible values; a non-mapping raises MdsError(code="mds::invalid_options").
  • compile_virtual / check_virtual / lint_virtual resolve imports against an in-memory map; entry must be a key in modules.
  • source_map=True generates a Source Map v3 document; result.source_map is a dict. For string-source compiles the source string is named "input.mds" — sources[0], unless the string @extends a base: then the chain's root base comes first. sources_content=True embeds the original source text in sourcesContent[] (requires source_map=True). ⚠ Privacy: sources_content=True embeds the full template source in the map.
  • rules is a mapping of rule name → severity string ("off", "info", "warn", "error"). Unknown severity values raise MdsError(code="mds::invalid_options"); unknown rule names emit a warning and lint continues — the unknown name has no effect, but a non-empty result.lint_warnings list signals the problem so callers can surface it. LintResult exposes .version, .truncated, .lint_warnings, .to_dict(), .to_json(), and .files — a list[LintFileReport]. Each LintFileReport has .file (str) and .diagnostics (list[LintDiagnostic]). LintDiagnostic carries .rule, .severity, .message, .help (str | None), .fixable (bool), .fix_edits (list[dict] | None), and .span (Span | None). LintFileReport and LintDiagnostic are frozen, picklable, and comparable by value. files[].file key: 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() vs to_json() asymmetry (source maps): CompileResult.to_dict() always includes "sourceMap": None when 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.

Metadata

Release files for markdown-script 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for markdown-script 0.5.1
File Size Uploaded Provenance Actions
markdown_script-0.5.1.tar.gz 776.2 kB With provenance Details for markdown_script-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for markdown-script 0.5.1
File Actions
markdown_script-0.5.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for markdown_script-0.5.1-cp311-abi3-win_amd64.whl
markdown_script-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for markdown_script-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl
markdown_script-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for markdown_script-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl
markdown_script-0.5.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for markdown_script-0.5.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
markdown_script-0.5.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for markdown_script-0.5.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
markdown_script-0.5.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for markdown_script-0.5.1-cp311-abi3-macosx_11_0_arm64.whl
markdown_script-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for markdown_script-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 6.7 MB

Release files / markdown_script-0.5.1.tar.gz

Download URL markdown_script-0.5.1.tar.gz
Size 776.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b4e32ad5629a6951396c62c5f0fcd892fc8b6192560cbcca1a07b442716f2d3
BLAKE2b-256 checksum
How to use checksums
9cdd276bc186a7e530dcbc821dcb6dffc2a458aaaf119be5761f158a38f5d1b1
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-win_amd64.whl

Download URL markdown_script-0.5.1-cp311-abi3-win_amd64.whl
Size 785.4 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
eaa8c47572a1586bc89467d4f1e341f17b84b5a71b3ce4efbfed9ba1e2fcaa97
BLAKE2b-256 checksum
How to use checksums
903e4fc77d7ac9eae80388d75a514c4fe098d17b0d85d986b76d1ebbaee043f7
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL markdown_script-0.5.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 1.0 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7bd073871246be9f28892973fd747fe0dc258a0971a59f380379c6a147c58753
BLAKE2b-256 checksum
How to use checksums
2cec7aff89d28e93de8232a65142acbd9a5fbfa837d6377bf3f3418a87206811
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL markdown_script-0.5.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 960.5 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
6d2f49f56b4df4bf2fc506bee74a053b4022852ffb992065f6458bed219ca3c8
BLAKE2b-256 checksum
How to use checksums
17253e9b7d59ff7603858b7c2cf267ece92fd4073b1d9158853dc6cab5ae9857
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL markdown_script-0.5.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 823.2 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fdee787895665f6c6a8d72a1e2583420384401e7a6a3e62a8c5b08878919d094
BLAKE2b-256 checksum
How to use checksums
8531f3db49f8b87a692fe41f24d9998abfefc31c5ef1fa713527fa14d73b1ce4
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL markdown_script-0.5.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 781.4 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
be4c77082ecb4ce2fce2fef11931a0192a4fe824a726531485ebdc1fb41f8d7c
BLAKE2b-256 checksum
How to use checksums
680a9370a692233e1654058d8bc29c81962ee84e18cd8b44d777a2f5ea64429c
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL markdown_script-0.5.1-cp311-abi3-macosx_11_0_arm64.whl
Size 755.7 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ffb56000ac01ad0a497bb0a2cb4eda40cb8fd7b51a9e62d2f30e683f5cf001fe
BLAKE2b-256 checksum
How to use checksums
d83a59b821a699161d42262376e5a12a2f4241461cdbdd3a96986eedc44184cc
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 Nov 20, 2026.

Transparency log

Release files / markdown_script-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL markdown_script-0.5.1-cp311-abi3-macosx_10_12_x86_64.whl
Size 786.6 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
670fe7125102ccc388961d7bffc2ebfe8009e957c89fed95a7306b6547fc5e9c
BLAKE2b-256 checksum
How to use checksums
c735520e1c34c499f859b1a06cb399cde8f77020c35e582aac8a2854c12ea054
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 Nov 20, 2026.

Transparency log

Security for markdown-script 0.5.1

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.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for markdown_script-0.5.1.tar.gz

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 Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page