mdformat-ruff
Mdformat plugin to ruffen Python code blocks
What it is and what it does
mdformat-ruff is a plugin for mdformat that applies ruff formatting rules to Python code blocks embedded in Markdown files. When installed, it automatically enables ruff as the code formatter for Python blocks when you run mdformat from the command line, or you can explicitly enable it via the mdformat Python API by passing python to the codeformatters parameter.
The plugin depends only on ruff and integrates into mdformat's plugin architecture. It works with Python 3.7 through 3.12 and is commonly used in documentation workflows and pre-commit hooks to ensure Python code examples in Markdown stay consistently formatted.
Use it for:
- Format Python code examples in project README and documentation files to match your ruff configuration.
- Enforce consistent code style in Markdown-based documentation as part of a pre-commit hook workflow.
- Automatically convert Python string quotes in code blocks when ruff is configured to do so.
- Maintain formatting consistency between Python code blocks in Markdown and the main codebase during CI/CD checks.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Integrates ruff code formatting into mdformat to automatically format Python code blocks within Markdown files.
Yes, if you use mdformat for Markdown formatting and want Python code blocks formatted by ruff. Install friction is minimal and the plugin integrates transparently. The aging maintenance status is a minor concern—no recent updates—but the package remains functional and unarchived with no known vulnerabilities. Suitable for documentation workflows where ruff is already your Python formatter.
Install
mdformat-ruff on PyPI
pip
pip install mdformat-ruffuv
uv add mdformat-ruffpoetry
poetry add mdformat-ruffInstalling mdformat-ruff
Before you install
Low friction install with a single runtime dependency (ruff). Maintenance status is aging—last release was over a year ago, though the repository remains unarchived.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal obligations.
Quickstart
pip install mdformat-ruff
import mdformat
unformatted = "```python\n'''ruff converts quotes'''\n```\n"
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""ruff converts quotes"""\n```\n'
Verify before relying
- Whether ruff version pinning (e.g., ruff==22.1.0) remains necessary for current versions.
- Compatibility with recent mdformat releases and how often updates are planned.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — ruff |
| Maintenance | aging — 915 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 122,041/month — #11,963 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mdformat_ruff-0.1.3-py3-none-any.whl
Keywords: mdformat, markdown, commonmark, formatter
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
mdformat-blackA plugin for mdformat that automatically…
permissive · top 15,000 on PyPI
mdformatMdformat is a CommonMark-compliant command-line…
permissive · top 5,000 on PyPI
ruff-formatProvides Python bindings to Ruff's code…
permissive · top 15,000 on PyPI
mdformat-tocMdformat-toc is an mdformat plugin that…
permissive · top 15,000 on PyPI
mdformat_mystmdformat-myst is an mdformat plugin that…
permissive · top 15,000 on PyPI
mdformat-gfmMdformat-gfm extends mdformat to format GitHub…
permissive · top 5,000 on PyPI
blacken-docsApplies Black code formatting to Python code…
permissive · top 15,000 on PyPI
mdformat_tablesmdformat-tables is a plugin for mdformat that…
permissive · top 15,000 on PyPI
md2SlackConverts Markdown syntax into Slack-compatible…
permissive · top 15,000 on PyPI
doccmdRuns linters, formatters, and other…
permissive · top 15,000 on PyPI