Skip to main content

pymdtools

PyPI version Wheel Documentation CI License: MIT

pymdtools is a Python toolkit for working with Markdown documents. It provides small, composable helpers to read, normalize, enrich, inspect, convert, and translate Markdown content.

The project is designed for practical documentation workflows: maintaining Markdown files, resolving reusable snippets, updating links, converting Markdown to HTML or PDF, and integrating with modern Markdown libraries such as Mistune and markdownify.

Features

  • Read and write text files with encoding-aware helpers.
  • Normalize Markdown content and Markdown files.
  • Manage reusable Markdown instructions stored in HTML comments:
    • variables;
    • include-file directives;
    • shared reference blocks;
    • generated include blocks.
  • Inspect and rewrite Markdown links.
  • Work with Markdown files through a high-level MarkdownContent wrapper.
  • Convert Markdown to HTML with Python-Markdown or Mistune.
  • Convert Markdown or HTML to PDF through pdfkit and wkhtmltopdf.
  • Apply PDF metadata, backgrounds, watermarks, and blank-page balancing.
  • Convert HTML fragments to Markdown through the external markdownify package.
  • Translate plain text and Markdown with the MyMemory API.

Installation

Install the published package from PyPI:

pip install pymdtools

For development, clone the repository and install the project dependencies:

git clone https://github.com/IIXIXII/pymdtools.git
cd pymdtools
python -m pip install -e ".[dev,docs]"

pymdtools supports Python 3.10 through Python 3.14.

Optional System Dependency

PDF generation uses pdfkit, which requires the external wkhtmltopdf executable. Install wkhtmltopdf separately if you need Markdown-to-PDF or HTML-to-PDF conversion. The executable is first resolved from PATH on every platform, with additional legacy installation folders checked on Windows.

On Windows, pymdtools searches common installation locations such as:

  • C:\Program Files\wkhtmltopdf
  • D:\Program Files\wkhtmltopdf
  • local wkhtmltopdf / software / third_party_software folders

Quick Start

Normalize Markdown text:

from pymdtools.normalize import md_beautifier

markdown = md_beautifier("# Title\n\nBody\n")

Work with a Markdown file:

from pymdtools.mdfile import MarkdownContent

doc = MarkdownContent("README.md")
doc["project"] = "pymdtools"
doc.title = "Project README"
doc.process_tags()
doc.write()

Resolve include references in a Markdown file:

from pymdtools.instruction import search_include_refs_to_md_file

search_include_refs_to_md_file("docs/page.md", backup_option=True)

Convert Markdown to PDF:

from pymdtools.mdtopdf import convert_md_to_pdf

pdf_path = convert_md_to_pdf("README.md")

Convert HTML to Markdown:

from pymdtools.markdownify_integration import markdownify

markdown = markdownify("<h1>Title</h1>")

Main Modules

  • pymdtools.common: shared path, filesystem, text, datetime, and validation helpers.
  • pymdtools.filetools: file-oriented wrappers such as FileName and FileContent.
  • pymdtools.instruction: Markdown comment directives, variables, refs, and includes.
  • pymdtools.mdcommon: Markdown link discovery and rewriting helpers.
  • pymdtools.mdfile: high-level MarkdownContent wrapper for editable Markdown files.
  • pymdtools.mdtopdf: Markdown, HTML, and PDF conversion pipeline.
  • pymdtools.mistune_integration: Mistune 3 compatibility layer.
  • pymdtools.markdownify_integration: wrapper around the external markdownify package.
  • pymdtools.normalize: Markdown normalization helpers.
  • pymdtools.translate: plain-text and Markdown translation helpers.

Documentation

The documentation is available on Read the Docs:

https://pymdtools.readthedocs.io/

To build it locally:

python -m pip install -r requirements-docs.txt
python -m sphinx.cmd.build -b html docs docs/_build/html

Development

Run the test suite:

python -m pytest

Run static type checking:

python -m pyright

Build the documentation in strict mode:

python -m sphinx.cmd.build -b html -W --keep-going docs docs/_build/html

Build and validate both distributions without publishing them:

python scripts/release.py build --allow-dirty

Security boundaries

  • HTML generation uses the escaping Mistune renderer by default. Selecting converter="markdown" explicitly enables raw HTML and is only appropriate for trusted Markdown.
  • Include directives can read local files from their configured search roots. Do not process untrusted directives, and provide explicit search folders for server-side workflows.
  • Translation sends document text to the external MyMemory service. Do not use it for secrets or regulated content without an appropriate data policy.

Release workflow

Versioning and publication are intentionally separated:

python scripts/release.py bump patch
git add pymdtools/version.py pymdtools/version.bat
git commit -m "Release 1.0.x"
python scripts/release.py tag
git push origin v1.0.x

The helpers refuse dirty trees, create only an annotated local tag, and never upload or push automatically. Creating a GitHub release from the verified tag triggers a build job without publishing credentials; a separate protected job then publishes those validated artifacts through PyPI trusted publishing. Historical tag mismatches can be reported, without changing them, with python scripts/release.py audit-tags.

Project Links

License

pymdtools is distributed under the MIT license. See LICENSE.md for details. Bundled layout resources and their license texts are inventoried in LICENSES-3rd-party.md.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymdtools-2.0.47.tar.gz (630.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymdtools-2.0.47-py3-none-any.whl (664.4 kB view details)

Uploaded Python 3

File details

Details for the file pymdtools-2.0.47.tar.gz.

File metadata

  • Download URL: pymdtools-2.0.47.tar.gz
  • Upload date:
  • Size: 630.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pymdtools-2.0.47.tar.gz
Algorithm Hash digest
SHA256 3d6c9b84dc78808092ebeba0b5490752974ea2c372d4f6c51f0f0855b88babda
MD5 bfee8f03918118bc85ef43b16a487a1d
BLAKE2b-256 d06e2d7779b5df3761323b62586ea1a7fd13f541f3593d82ba01c8ac25521f3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymdtools-2.0.47.tar.gz:

Publisher: publish.yml on IIXIXII/pymdtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymdtools-2.0.47-py3-none-any.whl.

File metadata

  • Download URL: pymdtools-2.0.47-py3-none-any.whl
  • Upload date:
  • Size: 664.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pymdtools-2.0.47-py3-none-any.whl
Algorithm Hash digest
SHA256 20d9983d860f4d138c10ae6633f32b87275c07c08b648e2501c8cbb37b346a86
MD5 1f0c12c3609045e218c792e934c4d9f7
BLAKE2b-256 5de91f3043ded91f7abf4bbe964bd5a476edfcb76bcec4ee5c82e6fc07c18456

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymdtools-2.0.47-py3-none-any.whl:

Publisher: publish.yml on IIXIXII/pymdtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page