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, a C compiler (for the TLS code of the network sender) 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, network=None, source_map=False, sources_content=False) -> CompileResult
compile_file compile_file(path, *, vars=None, network=None, source_map=False, sources_content=False) -> CompileResult
compile_virtual compile_virtual(modules, entry, *, vars=None, network=None, source_map=False, sources_content=False) -> CompileResult
compile_step compile_step(source, *, vars=None, base_path=None, network, state=None, source_map=False, sources_content=False) -> Step
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.

URL data entries (network=)

network is the network grant: {"allow": [...], "allow_imports": bool, "secrets": {...}, "allow_methods": [...], "strict_origins": bool}. allow holds 1 to 64 allow items, such as "api.example" or "http://127.0.0.1:8080". allow_imports is the opt-in for a URL entry of an imported module, False when absent. secrets holds at most 16 host secrets, {"NAME": {"value": ..., "origin": ...}}. allow_methods is the method grant: a list of 0 to 5 different effect methods, from "POST", "PUT", "PATCH", "DELETE" and "OPTIONS". GET and HEAD need no grant, so the list refuses them. An effect method is allowed in the entry module only. An effect request waits for the other requests of the compile, follows no redirect and is sent once. A mapping body becomes JSON, and a string body stays literal text. strict_origins refuses a request with a secret header or an effect method that references a runtime value or a URL entry of another origin, False when absent. Python has no repeated build, so network has no key for one. Without network, nothing is sent, and a URL entry with no runtime value raises MdsError(code="mds::network_denied").

  • compile, compile_file and compile_virtual with network= send the requests and compile again until the result is done. They make a new run key for each call, so network has no run_key there. The GIL is released for the whole request loop.
  • compile_step runs one step: the start, or a resume with state, the fetch state {"responses": {<request ID>: <response>}}. network is required and holds run_key: 64 lower-case hex digits. Make one random key for each compile, keep it for every step of that compile, and never log it or show it. A need step gives the Request objects that your code sends. Add each response under its request ID, and call again with the same arguments until the step is done.
  • Step, Request and RequestHeader are frozen, and Python code can not make them. repr of a Request shows its template form only (id, method, template, origin). url, headers and body (the body bytes, or None) are for the code that sends the request. A secret header has the secret name and the prefix, never the value.
  • check, lint, scan_imports and their file and virtual forms refuse the network keyword. The binding has no TLS root option and reads no mds.json file.

The fetch state form and the other rules are in spec §4.12 "Binding hosts".

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.9.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.9.0
File Size Uploaded Provenance Actions
markdown_script-0.9.0.tar.gz 1.1 MB With provenance Details for markdown_script-0.9.0.tar.gz

Built distributions (wheels)

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

Total release size: 15.3 MB

Release files / markdown_script-0.9.0.tar.gz

Download URL markdown_script-0.9.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
58789b3c3bf4921458fc9134623f11411f84a71dfa0bc0f6cd6006ca97ae503f
BLAKE2b-256 checksum
How to use checksums
f8749e52b9512a61c8f65f71030100cdedcc03e0a1d63d2d6142677e929c59a4
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-win_amd64.whl
Size 2.0 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
2c007f3ec7548df528b942aadb137ce42c71dbcc29855f0bf8f6cddb9cf43128
BLAKE2b-256 checksum
How to use checksums
0211073e84b1f3c16c8ec5b36d2751328e740abadf32a771446d7a2dfe33d0c2
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 2.3 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
933d87852fe641906293818284e96f3a775d50390faf206526a143607b094ff3
BLAKE2b-256 checksum
How to use checksums
60a24fee2aa5e46acd802aeeefa83f8464db598884d120de228c237a11bb6811
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 2.1 MB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
94847ef0bedc57c3646c3f5d5fd15a9862ae038e1463641f1298ef47f124c07d
BLAKE2b-256 checksum
How to use checksums
8ef7d000aad11f1eaf8d68bbc4e6513350ef92025bf9f9f17ea365c338b00658
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7a8b19aea5124d4d7f3e5a5e8c05e3fa73287c4ea40c0d8e8eecbdb250e2f376
BLAKE2b-256 checksum
How to use checksums
6455d157109592b5b712288b256d6d6425cb569c754bc03f5d34c6163f0ae3d0
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.9 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5c230bda7ac1de998dcbdd6fe025b903e63c5dddb061c21c9e8975040abe9ea5
BLAKE2b-256 checksum
How to use checksums
37a12c578642fcef0e02779f01eed3c10dd5081278bf8cd2962b2dc1e207fe42
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8cb0aa67a43689f43ea8733aa6a0b49380a4643034b91270826f77fb811765e6
BLAKE2b-256 checksum
How to use checksums
3b90e0a01df11f31e502849a2be7c67c8d6b306803fa30a4ed3674600fa39a42
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 Dec 1, 2026.

Transparency log

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

Download URL markdown_script-0.9.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b91d847d35a91d03bab37a4809f6e1ecd8b95a81680d5450348e2b3bcef3e899
BLAKE2b-256 checksum
How to use checksums
bc04f4e78209b7d9174d8fb617b1e49da37ddb255e3bb704c0516ac029dd71c7
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 Dec 1, 2026.

Transparency log

Security for markdown-script 0.9.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.9.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 Dec 1, 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