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.6.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.6.0
File Size Uploaded Provenance Actions
markdown_script-0.6.0.tar.gz 796.4 kB With provenance Details for markdown_script-0.6.0.tar.gz

Built distributions (wheels)

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

Total release size: 6.8 MB

Release files / markdown_script-0.6.0.tar.gz

Download URL markdown_script-0.6.0.tar.gz
Size 796.4 kB
Tags Source
SHA-256 checksum
How to use checksums
78e2d82266051dd62270f76f7d57743dcc37d1ec1543516eb6160cd55479bf5c
BLAKE2b-256 checksum
How to use checksums
865305428b24be665b926cc5bebf82b79a908250956afdd96275edd1b590d735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-win_amd64.whl
Size 798.7 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6b926cf5d45af5c2ab919c52e98ac2d03c2d84728adcab6fd4895830a07197d5
BLAKE2b-256 checksum
How to use checksums
368d09761f055ab05874c20de59f406c7a9b7867a7f2403444a6f5e7547f4ce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.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
1be2210f02ba18f1850963132846efaab131d1702d7ed43b5a79735d59f03b45
BLAKE2b-256 checksum
How to use checksums
595436c88b102aa29e832bedba66ea44327ef3361b5d45c8dd0b49fb6dc069df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 970.2 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
669a8d8dd96d27d2af8d54c42f8c9f0801193a1866b0ba8c72f307a090535969
BLAKE2b-256 checksum
How to use checksums
92668a55e8a9aec0cf8a486a43997dc106316c2e3d717b6a1e6030e38143e829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 835.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
9682d5837f4bc45a3fd3a82cb3943da517d4e28df189aa69952bccb8cf99609b
BLAKE2b-256 checksum
How to use checksums
883d260b3832d6927de42eda1d2edead76db582a3efd34c5e0a0f07478f39b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 791.3 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2e1816ac2e58b58a6f729731382ecc9e9c45862b4df53a1896f17db178278ddd
BLAKE2b-256 checksum
How to use checksums
09afca5fd94dc9d4174317176555f8136ed4a8d85445df3ee6ef8b23e8d47485
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-macosx_11_0_arm64.whl
Size 766.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2bbd84c20ffd30800c5ce5f06afe12fc168dd7604d4cbba2b18bcd9f48c28294
BLAKE2b-256 checksum
How to use checksums
776223321f7120ff6d97a2598b240bb120c36a465a3c26ff3d4ab3e5e9b16f7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

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

Download URL markdown_script-0.6.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 799.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e171315f1cb6f7710e2aef777833f9c186ac86d55877c1534bf008c693d73125
BLAKE2b-256 checksum
How to use checksums
40ef3a278a0896a1615e8a24ccc1a9d08246172cdabdf157cfc1bfdb3a7978a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 21, 2026.

Transparency log

Security for markdown-script 0.6.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.6.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 21, 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