Python-Markdown

raw JSON →
3.10.2 verified Tue May 12 auth: no python install: verified quickstart: verified

Python-Markdown is a full Python implementation of John Gruber's Markdown, providing a highly customizable parser for converting Markdown text to HTML. It is currently at version 3.10.2 and maintains an active release cadence, frequently addressing bug fixes, performance improvements, and Python version compatibility.

pip install markdown
error ModuleNotFoundError: No module named 'markdown'
cause The 'markdown' library or one of its extensions is not installed in the active Python environment, or the Python interpreter cannot find it due to incorrect environment paths or a conflicting local file.
fix
Install the library using pip: pip install markdown. If using extensions, ensure they are also installed, for example: pip install markdown[extra] or pip install pymdown-extensions.
error AttributeError: 'module' object has no attribute 'Markdown'
cause This usually happens when a user attempts to call 'markdown.Markdown()' as a constructor, but either a different 'markdown' module is imported (e.g., a local file named 'markdown.py' shadowing the installed library) or they are trying to access a non-existent attribute.
fix
Ensure you are importing the correct 'markdown' library and use the markdown.markdown() function for simple conversion, or correctly instantiate the Markdown class if using the advanced API: import markdown; html = markdown.markdown(text) or from markdown import Markdown; md = Markdown(); html = md.convert(text).
error AttributeError: 'module' object has no attribute 'version'
cause This error occurs because the way to access the library's version information changed in Python-Markdown version 3.0. Older code tries to use `markdown.version`.
fix
Access the version string using the standard Python module attribute: markdown.__version__.
error ImportError: cannot import name 'etree' from 'markdown.util'
cause This indicates a dependency conflict or an outdated extension attempting to import a utility function ('etree') from an internal module path ('markdown.util') that has either been removed or refactored in newer versions of Python-Markdown.
fix
Update Python-Markdown to the latest version (pip install --upgrade markdown) and ensure all installed extensions are compatible and up-to-date. If the issue persists, the problematic extension might need to be updated or replaced if it has not adapted to internal API changes.
error AttributeError: module 'markdown' has no attribute 'Markdown'
cause Users often incorrectly assume a class-based interface (e.g., `Markdown().convert()`) when the library provides a direct function call for conversion.
fix
Use the top-level markdown.markdown() function directly: import markdown; html = markdown.markdown(text)
breaking Python 3.9 support was officially dropped in Python-Markdown 3.10.0. Users on Python 3.9 or older must use a version prior to 3.10.0.
fix Upgrade to Python 3.10+ or pin `markdown<3.10.0` if unable to upgrade Python.
gotcha The default footnote ordering behavior changed in 3.9.0 (to order by reference appearance) but was reverted to definition order (`USE_DEFINITION_ORDER=True`) in 3.10.0 due to inconsistencies. If you upgraded from <3.9 to 3.9.x and relied on the new default, then upgraded to 3.10.x, your footnote order may have unexpectedly reverted.
fix Explicitly set the `USE_DEFINITION_ORDER` option in the footnotes extension (e.g., `extensions=['footnotes(USE_DEFINITION_ORDER=False)']`) to ensure consistent behavior across versions.
deprecated The `AbbrInlineProcessor` class and the `AbbrPreprocessor` class (renamed from `AbbrBlockprocessor`) were deprecated in version 3.7 as part of a refactor of the abbreviation extension. Custom code subclassing these will break.
fix Update custom abbreviation extension code to use the new `AbbrTreeprocessor` and `AbbrBlockprocessor` (which `AbbrPreprocessor` was renamed to) as described in the release notes or documentation.
gotcha Several patch releases (e.g., 3.8.1, 3.8.2, 3.10.1, 3.10.2) have fixed critical infinite loop vulnerabilities and parsing crashes when processing malformed HTML comments or incomplete tags, especially in newer Python versions like 3.14. Untrusted input could lead to denial-of-service.
fix Always ensure you are using the latest patch release (e.g., `3.10.2`) to benefit from critical parsing and security fixes, especially when processing user-provided Markdown.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.14s 18.5M
3.10 alpine (musl) - - 0.13s 18.5M
3.10 slim (glibc) wheel 1.6s 0.12s 19M
3.10 slim (glibc) - - 0.13s 19M
3.11 alpine (musl) wheel - 0.18s 20.5M
3.11 alpine (musl) - - 0.20s 20.5M
3.11 slim (glibc) wheel 1.6s 0.15s 21M
3.11 slim (glibc) - - 0.15s 21M
3.12 alpine (musl) wheel - 0.15s 12.3M
3.12 alpine (musl) - - 0.16s 12.3M
3.12 slim (glibc) wheel 1.5s 0.15s 13M
3.12 slim (glibc) - - 0.15s 13M
3.13 alpine (musl) wheel - 0.14s 12.0M
3.13 alpine (musl) - - 0.15s 11.9M
3.13 slim (glibc) wheel 1.5s 0.14s 13M
3.13 slim (glibc) - - 0.15s 12M
3.9 alpine (musl) wheel - 0.09s 18.3M
3.9 alpine (musl) - - 0.11s 18.3M
3.9 slim (glibc) wheel 2.0s 0.08s 19M
3.9 slim (glibc) - - 0.09s 19M

Initialize the Markdown parser with optional extensions and convert a Markdown string to HTML. Extensions like 'fenced_code' for code blocks and 'tables' for table support are commonly used.

import markdown

markdown_text = """
# My Title

This is **bold** and *italic* text.

- Item 1
- Item 2
"""

html_output = markdown.markdown(markdown_text, extensions=['fenced_code', 'tables'])
print(html_output)