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.0

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.0
File Size Uploaded Provenance Actions
markdown_script-0.5.0.tar.gz 774.0 kB With provenance Details for markdown_script-0.5.0.tar.gz

Built distributions (wheels)

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

Total release size: 6.7 MB

Release files / markdown_script-0.5.0.tar.gz

Download URL markdown_script-0.5.0.tar.gz
Size 774.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0950cfda352c2bfb48f335066707b4fa4f5bc0190e346671228bbba5c76cc4a0
BLAKE2b-256 checksum
How to use checksums
dc03253605b5d43df8af9a8943aa078f07e04ba85c898f67fda249500190b8f0
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.0-cp311-abi3-win_amd64.whl

Download URL markdown_script-0.5.0-cp311-abi3-win_amd64.whl
Size 784.0 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8a6d5edf26c39d5cb15fb6198a10066368642318a68ada2a7681efc25f912914
BLAKE2b-256 checksum
How to use checksums
d860e772a38ed85255514e85b3df38f05667c56d042f7b0e200987873233cc5e
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.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL markdown_script-0.5.0-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
c17d7f37827b188a5a533f409e8e4ab5c97e4949d7e028f846ab0d008dcc218f
BLAKE2b-256 checksum
How to use checksums
0e162af6b97ea0a0a05a4f2e49fe0b2d84a5a0076218eb16bd21c61ba59f920b
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.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL markdown_script-0.5.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 957.2 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
283ade60c54f7ab0ef7894e7597a29a9a76ace629b2608b9e0a3c649ebf961be
BLAKE2b-256 checksum
How to use checksums
f24eb1655a4518e2d22408a4bc36bef7362245327124c13a38ab0793aef7306b
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.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL markdown_script-0.5.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 822.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
92d0c4ffff011040a46cb30c45e904f3aa5fbc6e65ad87451412e5b55609f56d
BLAKE2b-256 checksum
How to use checksums
6e1ebf33fcb909c43ec8a613d4b40fce5dc995a2240ee76e76546839d6f7b74c
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.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL markdown_script-0.5.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 778.7 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
10cb406c5c055ad3f64101ed7729d859febbb86296117e19f9d8fcfb326de1ce
BLAKE2b-256 checksum
How to use checksums
7132188259d3204d0e3dc5d020021164c89cbff95c1e534fc541ba1855334f12
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.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL markdown_script-0.5.0-cp311-abi3-macosx_11_0_arm64.whl
Size 751.9 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a8b8d9d5d95bd779e005e920d41e258960b0e5f32b71e57670fcf40a0bde9030
BLAKE2b-256 checksum
How to use checksums
1c3ae2770d4c3dd4de84424d959e76274d48a317d0d8490777129ee8382ccb5f
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.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL markdown_script-0.5.0-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
16a57a4a79456b496c9ad09cac63d0e009022510ae1256e21a103f981a14e877
BLAKE2b-256 checksum
How to use checksums
79e9f84f09a0ef05f7dc2ce375b3dc79ea268605a8703f259fbdbde0c6c5c3f1
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.0

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.0.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