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 sources[0] is "input.mds". 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.

Release files for markdown-script 0.4.3

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.4.3
File Size Uploaded
markdown_script-0.4.3.tar.gz 553.6 kB Details

Built distributions (wheels)

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

Total release size:6.0 MB

Release files / markdown_script-0.4.3.tar.gz

Download URL markdown_script-0.4.3.tar.gz
Size 553.6 kB
Tags Source
SHA-256 checksum
How to use checksums
65f530c511c04889b9c55b7ba8c5cc4bf9a641c79c2c4d5bad4149be1b36288b
BLAKE2b-256 checksum
How to use checksums
f8c9357e5bdfefab5e89b8832482b72006b5dcd3e71d8e8b484c25827fd4e560
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-win_amd64.whl
Size 690.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
27d48aa9c5a9198d681eb5954edc7ddb7ac8b563528926dcc5ffe88d62a4c1dd
BLAKE2b-256 checksum
How to use checksums
9cdce512870a0458e240394eb2ca2ceabc88dffb2e27d9a3d1d5de613826d7fe
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-musllinux_1_2_x86_64.whl
Size 964.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
28c399d8c4101d1d698541a537d8ec0119a53bdbdf91de54bc8622137ddedff1
BLAKE2b-256 checksum
How to use checksums
ef83e5e597f3ac306f20ce8b7cac06fdb4b621f808c8d943fbcad4955615a362
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-musllinux_1_2_aarch64.whl
Size 894.6 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
90a47f69acd84b3771aada58249a524448ef542a9b23824e036b49213314324d
BLAKE2b-256 checksum
How to use checksums
e53eaf4d9b76a014831731fd7bfb78021654e6f08e7f33eb5995e8ee2496538e
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 751.1 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1be3b7b8fe4dc8fb943dd4cb258a1eaecd57c386418fcd643d28e72c2df86c00
BLAKE2b-256 checksum
How to use checksums
f59b1472cb89c27ce9b6bab75ff7820747656dc232e5027f0822af86495c1d9c
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 715.2 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a6d96f7b4ea8ed157883e4a9751ca6465bb0a47fed1e78ce44f7a2f98260938d
BLAKE2b-256 checksum
How to use checksums
24d00583e16d44f87a842db4cfe685e72c1ba1798351a1327ea57bec7c1781b8
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-macosx_11_0_arm64.whl
Size 686.4 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0a70587390ea9a438436fd9649f6b771b0b7d760454f01d36f355af313dce178
BLAKE2b-256 checksum
How to use checksums
338ea66193819c241f768cb443fcb7d8cafb115e017966ea1f7d21509ae7c2a4
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 17, 2026.

Transparency log

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

Download URL markdown_script-0.4.3-cp311-abi3-macosx_10_12_x86_64.whl
Size 712.9 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c09218245cb9e560a5b51cbc537b452a7518aebe6524b2fff85e1897e4292bbe
BLAKE2b-256 checksum
How to use checksums
0bb7172021a0c30027ecb14f0c2dea03741ed316d47aff1cd32d57c05c267f00
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 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.3 This release

8 release files

0.4.2

8 release files

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