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 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": ...}}. 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 and headers 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.8.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.8.0
File Size Uploaded Provenance Actions
markdown_script-0.8.0.tar.gz 1.1 MB With provenance Details for markdown_script-0.8.0.tar.gz

Built distributions (wheels)

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

Total release size: 14.9 MB

Release files / markdown_script-0.8.0.tar.gz

Download URL markdown_script-0.8.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
dfb5bd1847eb3f81178ab30e3566803fb03b75c96d77f276dc083ead8d005800
BLAKE2b-256 checksum
How to use checksums
dddc46fbb9bd65240dd31bfeaecf991a7cdaf47998fa9784b96733fe4f9c43b3
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
54f7a870fd65249201153a05a90d5fde7e63b98f98fdc7eef5b1cbc26fd5ca4c
BLAKE2b-256 checksum
How to use checksums
12f51ff8263abd042105607de928a28b74c994e476b4a25fb6c831a89556cc0d
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
d5a6fbabe678bb2b46bec0d35f63636c5d090b65cba867c0444166d0a9cb5b83
BLAKE2b-256 checksum
How to use checksums
11728e9294f0b2bd7d1e0d15758fd09ed55f99bdf0129ae4d534edf4962630fb
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
9a74daa3122bbbd486086700c30e68bd3947bd48034271316a22c81018885337
BLAKE2b-256 checksum
How to use checksums
ea580fc446ab45dd10d3f3baaf49cf4af54d248a95ce6f87919f50f242d9549f
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
8aeecc6ca4c9b88427937545aca7f735423b48ce6b07385f6ce720c6a98b0370
BLAKE2b-256 checksum
How to use checksums
f3a924f8455fffc5fb7c46a75ac27cb728db8866be1707a99cb1321caa12d492
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
640b57b0dc71941b629f2e628956edbd77bb868272788c9261b9dfbb3667d3b1
BLAKE2b-256 checksum
How to use checksums
a130d0565f3ceda29f61252ced5e8435ef3d6cd586faddf8c7f3fe9da372892d
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
22589afec65002a47ec149ff15adc4d362f303adc12d71143e578370e42512d8
BLAKE2b-256 checksum
How to use checksums
d42708833d2c97147c5c992f5592a497ca2cfb41be4057651cfe82d4661c39df
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 30, 2026.

Transparency log

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

Download URL markdown_script-0.8.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
2235281388db4d9766ae643ae1b303b66fb14344c92bcda58641acdc83386180
BLAKE2b-256 checksum
How to use checksums
8c5823fe9cee047bec02235810e0395556d34825db1d5c80ff2ec9acf5b1b539
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 30, 2026.

Transparency log

Security for markdown-script 0.8.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.8.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 30, 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