Skip to main content

pymdtools

PyPI version Documentation CI License: MIT

pymdtools is a Python library for inspecting, transforming and publishing Markdown documents. Assemble reusable sections, edit links, normalize formatting, generate HTML or PDF, and translate text through an injectable client.

Python 3.10–3.14 is tested in CI on Linux and Windows, with additional macOS checks. Core Markdown and HTML features work without a browser or PDF dependencies.

Installation

Install into your Python environment:

python -m pip install pymdtools

For PDF output, install the extra and the browser in the same environment:

python -m pip install "pymdtools[pdf]"
python -m playwright install chromium

On Linux, use python -m playwright install --with-deps chromium to install browser system libraries as well. See the installation guide for virtual environments and source installations. The examples and developer scripts below belong to the repository or source archive; they are not installed as commands by the wheel.

First document

This example creates build/hello.md and build/hello.html, together with the HTML layout's assets. Running it again replaces the generated files; Markdown writes keep a dated backup by default.

from pathlib import Path

from pymdtools.mdfile import MarkdownContent
from pymdtools.mdtopdf import convert_md_to_html

output = Path("build")
output.mkdir(exist_ok=True)
document = MarkdownContent(
    content="# Welcome\n\nProject: <!-- begin-var(project) --><!-- end-var -->\n"
)
document["project"] = "pymdtools"
document.process_tags()
document.write(output / "hello.md")
html_path = convert_md_to_html(output / "hello.md", layout="github")
print(html_path)

Open the HTML file in a browser. Keep its adjacent _pymdtools_assets/ directory when copying or publishing the page. To also produce build/hello.pdf, after installing PDF support:

from pymdtools.mdtopdf import convert_md_to_pdf
from pymdtools.options import PdfFeatures
from pymdtools.pdf_backend import PdfOptions

pdf_path = convert_md_to_pdf(
    "build/hello.md",
    options=PdfOptions(page_format="A4", timeout=60),
    features=PdfFeatures(metadata={"title": "Welcome", "author": "Example team"}),
)

Choose a workflow

Task Public entry point Guide
Edit documents, titles and variables pymdtools.mdfile.MarkdownContent Documents
Resolve snippets and shared sections pymdtools.instruction Directives
Find, rename and rebase links pymdtools.mdcommon Links
Normalize Markdown pymdtools.normalize Normalization
Generate HTML, PDF and overlays pymdtools.mdtopdf Conversion
Convert HTML to Markdown pymdtools.markdownify_integration HTML input
Translate text and Markdown pymdtools.translate Translation
Read files, process trees and load templates pymdtools.common, pymdtools.filetools File tools

The example catalogue contains 25 focused scripts and one complete workflow, with local sample data and expected outputs. From a checkout, after installing the package:

python -m pip install -e .
python examples/run_all.py --list
python examples/run_all.py
python examples/22_report_pipeline.py

The default runner executes 23 scenarios with core dependencies. Results go to examples/output/<example>/. Install .[pdf] and Chromium before using --only-pdf for the three PDF scenarios, or --pdf for all 26.

Behavior to know

  • Link inspection and edits use CommonMark source positions. Duplicate link occurrences are preserved, reference identifiers are case-insensitive, and images and code are excluded from ordinary link discovery.
  • Normalization returns the input unchanged if the candidate changes CommonMark rendering or fails its idempotence check. Extensions used by other Markdown dialects need validation against representative documents.
  • MarkdownContent.process_tags() changes the in-memory buffer; call write() to save it. include-file accepts a filename, with directories supplied through IncludeOptions(search_folders=...). Reference discovery scans each root only by default; set refs_depth=-1 explicitly for recursion.
  • HTML conversion uses an escaping Mistune renderer by default. The explicit converter="markdown" alternative preserves raw HTML and needs trusted input. File inclusions also need trusted documents and deliberate search roots.
  • PDF rendering disables JavaScript and remote resources by default. Local assets are confined to the HTML directory and permitted source asset root. PdfOptions.timeout limits the Chromium worker lifetime, including startup; it does not cover separate Markdown conversion or PDF post-processing.
  • Translation uses the external MyMemory service unless a custom transport is supplied. The repository's translation examples run entirely offline.

See the options reference, troubleshooting guide and changelog for defaults, errors and migration details.

Development and documentation

From the repository root, create the locked development environment:

python -m pip install uv==0.12.19
uv sync --locked --extra dev --extra docs --extra pdf
uv run --no-sync pytest
uv run --no-sync python -m sphinx.cmd.build -W --keep-going -b html docs docs/_build/html
uv run --no-sync python -m sphinx.cmd.build -W --keep-going -b doctest docs docs/_build/doctest

Open docs/_build/html/index.html. Chromium is only required for the optional PDF examples and integration test. See CONTRIBUTING.md for lint, types, VS Code, distributions and CI, and the release guide for versioning and publication. The library lives in src/pymdtools.

Original Python code and sample data use the MIT license. Bundled layouts retain their own terms and attribution; the resource inventory also records unresolved permissions for historical themes. Installed dependencies have separate licenses, including GPL/LGPL components; see the dependency inventory.

Metadata

Release files for pymdtools 2.1.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 pymdtools 2.1.0
File Size Uploaded
pymdtools-2.1.0.tar.gz 973.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymdtools 2.1.0
File Interpreter ABI Platform
pymdtools-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.8 MB

Release files / pymdtools-2.1.0.tar.gz

Download URL pymdtools-2.1.0.tar.gz
Size 973.1 kB
Tags Source
SHA-256 checksum
How to use checksums
86f1370358dc07223479a5c343ec715c78cc47a91209aa341f4e2a02670d7cf6
BLAKE2b-256 checksum
How to use checksums
dd8164d15d40c055017b4dd321682a3f9398c8a7a7f5e0f4c77e001409db32c9
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 27, 2026.

Transparency log

Release files / pymdtools-2.1.0-py3-none-any.whl

Download URL pymdtools-2.1.0-py3-none-any.whl
Size 803.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a264b900e32c342113694a925ba70ae07c74aad5bfa89d4e327da3670a388006
BLAKE2b-256 checksum
How to use checksums
62c19637669cdaca850b514c537df1942ed8f0b812b75a17f5eb88bea2bb5820
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 27, 2026.

Transparency log

Release history Release notifications | RSS feed

3.0.0

2 release files

2.1.1

2 release files

This release

2.1.0 This release

2 release files

2.0.47

2 release files

1.0.21

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.10

2 release files

1.0.8

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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