Skip to main content

QMDC Parser (Python)

QMDC ↔ JSON parser for Markdown with lossless round-trip support.

Installation

cd qmdc-py
uv pip install -e .

CLI Usage

Parse (QMD.md → JSON)

# File → stdout
qmdc parse -i doc.qmd.md

# Stdin → stdout
echo "## Test [[test]]" | qmdc parse

# File → file
qmdc parse -i doc.qmd.md -o output.json

# Without metadata
qmdc parse -i doc.qmd.md --no-comments --no-syntax

# Compact JSON
qmdc parse -i doc.qmd.md --no-pretty

Rebuild (JSON → QMD.md)

# File → stdout
qmdc rebuild -i data.json

# Stdin → stdout
echo '[{"__id":"test","name":"Test"}]' | qmdc rebuild

# File → file
qmdc rebuild -i data.json -o doc.qmd.md

Formatting (parse → rebuild)

There is no separate lint command. Canonical formatting (like ruff/prettier) is the lossless round-trip through parse → rebuild:

# Canonical formatting
qmdc parse -i doc.qmd.md | qmdc rebuild

Programmatic API

from qmdc import parse, rebuild

# Parse QMD.md → JSON
markdown = """
## User [[user]]

- name: Alice
- age: 30
"""
result = parse(markdown)
# [{"__id": "user", "__label": "User", "name": "Alice", "age": 30, ...}]

# Rebuild JSON → QMD.md
qmdc = rebuild(result)
# "## User [[user]]\n\n- name: Alice\n- age: 30\n"

Testing

# From the project root
make test

# Python tests only
make py-test

# pytest directly
cd qmdc-py
uv run pytest tests/ -v

Workspace (multi-file parsing)

QMDC Parser supports workspaces — a set of related QMD.md files with cross-file reference validation.

Workspace CLI

# Parse a workspace into JSON
qmdc workspace parse ./my-project -o workspace.json

# Validate a workspace
qmdc workspace validate ./my-project

# Rebuild files from JSON
qmdc workspace rebuild workspace.json -o ./output

Query (SQL queries against a workspace)

# SQL query against a workspace (loads all workspaces recursively)
qmdc query ./my-project "SELECT __id, __kind, __label FROM objects WHERE __kind = 'Service'"

# With JSON output
qmdc query ./my-project "SELECT * FROM objects LIMIT 10" --format json

# Query via a Query object (reference to a [[id:Query]] object in the workspace)
qmdc query ./my-project "#all_services"

# Count objects and edges
qmdc query ./my-project "SELECT COUNT(*) as total FROM objects"
qmdc query ./my-project "SELECT COUNT(*) as edges FROM edges"

The query command automatically:

  • Recursively finds every QMDC workspace under the given folder
  • Parses all files and loads objects into SQLite
  • Extracts graph edges from references between objects
  • Runs the SQL query against the database

Available tables:

  • objects — all objects with __id, __kind, __label, __file, __line, data (JSON)
  • edges — all graph edges with source_id, target_id, field_name

Workspace API

from qmdc import execute_query, parse_workspace, scan_workspace, workspace_to_json

# Scan files
files = scan_workspace("my-project")
# ['readme.qmd.md', 'api.qmd.md', 'tables.qmd.md']

# Parse the whole workspace; validation errors come with it
result = parse_workspace("my-project")
for error in result.errors:
    print(error.type, error.file, error.line, error.message)
# broken_link api.qmd.md 4 Object 'no_such_object' not found

# SQL over the objects and the reference graph
tables = execute_query(workspace_to_json(result), "SELECT __id FROM objects WHERE __kind = 'Table'")
# tables.rows == [['users']]
refs = execute_query(workspace_to_json(result), "SELECT source_id, edge_type FROM edges")
# refs.rows == [['my_project::get_users', 'returns']]

See the format specification for the full spec.

Status

✅ Fully implemented:

  • Tokenizer (markdown-it-py)
  • Header parser (all variants: [[id]], [[id:Kind]], [[:Kind]])
  • Field parser (primitives: string, number, boolean, null)
  • Nested objects (H1–H6)
  • Arrays (YAML notation, Markdown lists, object arrays)
  • Tables
  • Comments (__comments)
  • Syntax metadata (__syntax)
  • Types metadata (__types)
  • YAML multiline syntax (|)
  • Rebuild (canonical form)
  • YAML blocks
  • JSON blocks
  • Document title (H1 without [[id]])
  • Lossless round-trip (__level, __has_explicit_id)
  • CLI: parse, rebuild
  • Workspace: multi-file parsing with reference validation

License

AGPL-3.0-or-later © mikilabs

Metadata

Release files for qmdc 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for qmdc 2.0.2
File Actions
qmdc-2.0.2-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for qmdc-2.0.2-py3-none-win_arm64.whl
qmdc-2.0.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for qmdc-2.0.2-py3-none-win_amd64.whl
qmdc-2.0.2-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details for qmdc-2.0.2-py3-none-musllinux_1_1_x86_64.whl
qmdc-2.0.2-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for qmdc-2.0.2-py3-none-manylinux_2_28_aarch64.whl
qmdc-2.0.2-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for qmdc-2.0.2-py3-none-manylinux_2_17_x86_64.whl
qmdc-2.0.2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for qmdc-2.0.2-py3-none-macosx_11_0_arm64.whl
qmdc-2.0.2-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for qmdc-2.0.2-py3-none-macosx_10_12_x86_64.whl

Total release size: 31.2 MB

Release files / qmdc-2.0.2-py3-none-win_arm64.whl

Download URL qmdc-2.0.2-py3-none-win_arm64.whl
Size 4.1 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
c3b384b7467f763d600ba9b733edf6b16b326ebb5121cb7af571ce4ecbdbeda5
BLAKE2b-256 checksum
How to use checksums
b65e6fdc2a90fdd363b6ab99d718e3d292c6b5d92bbb538249d4a9ea0dc8cee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-win_amd64.whl

Download URL qmdc-2.0.2-py3-none-win_amd64.whl
Size 4.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ce7ae577085521eb1e114011e5e0b9591613213212652cc5ac054d6c5992f1b3
BLAKE2b-256 checksum
How to use checksums
d223a3bf399bd38bf2b63743ed04844a721c5acdfd7fbca65f5697c39fe2f371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-musllinux_1_1_x86_64.whl

Download URL qmdc-2.0.2-py3-none-musllinux_1_1_x86_64.whl
Size 4.6 MB
Tags Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
559b9f2483d340ab95d3f0c9489f443dd64df8a3a56b3a9932ed4be331861b9c
BLAKE2b-256 checksum
How to use checksums
e5ef3141c640060e4c72258600e04d828d66e2e995c311e25046a96a761f6189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-manylinux_2_28_aarch64.whl

Download URL qmdc-2.0.2-py3-none-manylinux_2_28_aarch64.whl
Size 4.3 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
018b677e2f2b568a14ba6327708054c634d903a77cabe83df971f522b532b8ed
BLAKE2b-256 checksum
How to use checksums
b8cfc4d5b2627e6e8b284d3a4222d6e46260d857ab4b32e4d317ab7f214985f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-manylinux_2_17_x86_64.whl

Download URL qmdc-2.0.2-py3-none-manylinux_2_17_x86_64.whl
Size 4.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
649ff1e69a39dd1628fef9124901c4ee53fc963dd0ee6858d5ede93fd9fe8ae4
BLAKE2b-256 checksum
How to use checksums
afa915b7b5072d86f91a44d47da3d5ebe2befff670e7957391fdc4e69464d394
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-macosx_11_0_arm64.whl

Download URL qmdc-2.0.2-py3-none-macosx_11_0_arm64.whl
Size 4.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
02455e00ac8bc205445635e0d81674561c784ae3caecb84554461731c7bcff76
BLAKE2b-256 checksum
How to use checksums
32c84845ffa30b07a6733fc56f1a8f2ecd3a0e17c222bf05c27e01f541132f9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / qmdc-2.0.2-py3-none-macosx_10_12_x86_64.whl

Download URL qmdc-2.0.2-py3-none-macosx_10_12_x86_64.whl
Size 4.7 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
60acfacaa70a27b7e2afec8b0f0c22208dd58cee3247d58644489dec89efb9fa
BLAKE2b-256 checksum
How to use checksums
284ec9de189925227e610cd444ed97f0360caded444b371821018344c572bb19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for qmdc 2.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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