mdformat-black
Mdformat plugin to Blacken Python code blocks
What it is and what it does
mdformat-black is a plugin that extends mdformat to apply Black's Python code formatting rules to Python code blocks within Markdown files. When installed, mdformat automatically recognizes and formats Python code blocks using Black's conventions—converting quote styles, enforcing line length, and applying other Black rules—while leaving the rest of your Markdown untouched.
The plugin works both from the command line (automatically after install) and programmatically via mdformat's Python API (where you must explicitly enable it by passing `codeformatters={"python"}` to mdformat.text()). It requires Python >=3.6,<4.0 and depends on mdformat and black as runtime dependencies.
Use it for:
- Automatically format Python code examples in technical documentation to match your project's Black style.
- Ensure consistency between code snippets in README files and your actual codebase formatting.
- Integrate Python code block formatting into a Markdown linting or CI pipeline alongside mdformat.
- Format Python code blocks in blog posts or tutorials written in Markdown without manual editing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A plugin for mdformat that automatically formats Python code blocks in Markdown files using Black's code style rules.
Yes, if you use mdformat and want Python code blocks in your Markdown to follow Black's style. The low install friction, permissive license, and lack of known vulnerabilities make it straightforward. However, the aging maintenance status (last release 2020-09-24) means you should verify compatibility with your current Black and mdformat versions before relying on it in production workflows.
Install
mdformat-black on PyPI
pip
pip install mdformat-blackuv
uv add mdformat-blackpoetry
poetry add mdformat-blackInstalling mdformat-black
Before you install
Low install friction with just two runtime dependencies. The package is aging—last release was 2020-09-24 and last commit 2025-03-09—but remains unarchived.
License in practice
MIT license is permissive; you can use, modify, and distribute freely with minimal restrictions.
Quickstart
pip install mdformat-black
import mdformat
unformatted = "```python\n'''black converts quotes'''\n```\n"
formatted = mdformat.text(unformatted, codeformatters={"python"})
assert formatted == '```python\n"""black converts quotes"""\n```\n'
Requires mdformat and black to be installed; Python >=3.6,<4.0
Verify before relying
- Whether the package works reliably with recent versions of black and mdformat beyond classifier claims.
- Whether there are known incompatibilities with Python 3.9+ despite the 'supports_current' designation.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.6,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — mdformat, black |
| Maintenance | aging — 2,150 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 114,372/month — #12,299 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mdformat_black-0.1.1-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-ruffIntegrates ruff code formatting into mdformat…
permissive · top 15,000 on PyPI
pyinkPyink is a Python code formatter forked from…
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
mdformatMdformat is a CommonMark-compliant command-line…
permissive · top 5,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
blacken-docsApplies Black code formatting to Python code…
permissive · top 15,000 on PyPI
mdformat-gfm-alertsA plugin for mdformat that formats GitHub…
permissive · top 15,000 on PyPI
mdformat_tablesmdformat-tables is a plugin for mdformat that…
permissive · top 15,000 on PyPI
mdformat-mkdocsAn mdformat plugin that formats Markdown for…
permissive · top 15,000 on PyPI