python-markdownify

Convert HTML into clean, configurable Markdown from Python with fine-grained control over tags, escaping, and formatting.

Library
PyPI
v1.2.3
2,254 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
51 /100 Fair
Development Activity 16
Maintenance 32
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 74
Code Quality 78
Innovation 58
Learning Curve 85

Markdownify is a focused Python library that turns HTML into Markdown, exposing a simple markdownify() function alongside a subclassable MarkdownConverter class for anyone who needs more control than a one-shot conversion offers. It wraps BeautifulSoup for HTML parsing, then walks the resulting tree tag by tag, dispatching to a convert_<tagname> method for each element type, which makes the codebase easy to extend by simply overriding or adding methods on a subclass.

The library is opinionated about correctness at the edges: it ships options for heading style (ATX, ATX-closed, or underlined/Setext), bullet rotation across nested lists, strong/emphasis symbol choice, table header inference, and multiple escaping modes for characters that would otherwise be misread as Markdown syntax. This attention to escaping and edge-case handling is what distinguishes it from simpler HTML-stripping approaches, and it is why the project is a common dependency wherever HTML content (emails, CMS fields, scraped pages, LLM tool output) needs to become readable Markdown.

What You Get

  • A markdownify() function that converts an HTML string to Markdown in one call, with dozens of formatting options exposed as keyword arguments.
  • A MarkdownConverter base class with one convert_<tag> method per supported HTML element, so custom tag handling is a matter of overriding a single method in a subclass.
  • A markdownify CLI entry point for converting HTML files or piped stdin to Markdown from the shell, sharing the same option set as the Python API.
  • Configurable heading styles (ATX, ATX_CLOSED, UNDERLINED), bullet character rotation for nested lists, and a choice of * or _ for strong/emphasis symbols.
  • Multiple escaping modes (escape_asterisks, escape_underscores, escape_misc) that prevent converted text from accidentally producing unintended Markdown syntax.
  • Support for converting directly from a BeautifulSoup object via convert_soup(), avoiding a redundant parse when the caller already has a soup tree.

Common Use Cases

  • Converting HTML email bodies or CMS rich-text fields into Markdown for storage, diffing, or downstream rendering.
  • Feeding scraped or fetched web page HTML into an LLM pipeline as clean Markdown context instead of raw markup.
  • Building documentation tooling that needs to migrate HTML content (e.g. exported wiki pages) into a Markdown-based static site generator.
  • Writing custom exporters that need selective control over which HTML tags are converted versus stripped entirely.

Under The Hood

Architecture Markdownify is a small, single-module library centered on MarkdownConverter in markdownify/__init__.py. It parses input HTML with BeautifulSoup, then recursively walks the resulting tag tree, converting each node’s children first and passing the accumulated text plus a parent_tags set into a per-tag convert_<tagname> method (heading levels 1-6 are unified through a convert_hN dispatcher via a regex on the method name). This dispatch-by-naming-convention pattern is the core extension point: subclasses override or add convert_* methods to change or add tag behavior without touching the traversal logic itself. A separate main.py module wraps the same markdownify() entry point in an argparse CLI, keeping the library and CLI concerns cleanly split.

Tech Stack The library targets Python and depends on beautifulsoup4 for HTML parsing (with a pluggable underlying parser via bs4_options, defaulting to the stdlib html.parser) and six for legacy Python 2/3 compatibility helpers, reflecting the project’s long history dating to 2012. Packaging uses a modern pyproject.toml with setuptools and setuptools_scm for version derivation from git tags, and the project ships a py.typed marker plus a hand-written .pyi stub file so consumers get static type checking despite the implementation itself not being fully type-annotated.

Code Quality Tests are organized by concern across dedicated files (test_basic.py, test_conversions.py, test_tables.py, test_lists.py, test_escaping.py, test_advanced.py, test_args.py, test_custom_converter.py) and run with pytest through tox, alongside flake8 linting and restructuredtext-lint for the README. A second CI job runs mypy and mypy --strict against the stub-covered surface, giving the project real type-checking coverage even though the runtime code favors plain Python over inline type hints. Error handling is minimal by design — this is a text-transformation library with few failure modes beyond malformed input, which BeautifulSoup already tolerates.

What Makes It Unique What sets Markdownify apart from simpler HTML-to-text strippers is its systematic handling of Markdown’s own syntax collisions: dedicated regexes escape sequences that would otherwise be misread as headings, list markers, or emphasis when they appear in converted text (e.g. a line starting with digits and a period, or a run of # characters). Combined with the override-one-method extension model, this makes it a common building-block dependency for projects that need correct, customizable Markdown output rather than a quick-and-dirty text extraction.

Used by 12 apps in this directory

TypeScript
55%
Other

agenta

AI Development · Developer Tools · Devops

4,823

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 55%
Python 40%
Updated yesterday
Python
99%
MIT

deepagents

AI Agents · AI Development

30,090

The batteries-included Python agent harness — planning, sub-agents, filesystem, shell, memory, and skills bundled in, built on LangGraph.

View details
88
Repo Health
83
Technical
70
Dependency
Built with
Python 99%
Updated today
Python
100%
MIT

Graphify

AI Agents

125,080

A YC-backed, open-source knowledge graph skill for AI coding assistants — type /graphify and it maps your entire project (code, docs, PDFs, images, videos) into a queryable graph instead of grepping through files.

View details
84
Repo Health
73
Technical
72
Dependency
Built with
Python 100%
Updated today
Go
86%
MIT

Hatchet

AI Development · Automation · Developer Tools

8,091

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
67
Dependency
Built with
Go 86%
Updated yesterday
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,614

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
63
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,699

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
82
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 2 days ago
Python
97%
MIT

local-deep-researcher

AI Assistants · AI Development

9,364

A fully local web research assistant that iteratively searches, summarizes, and refines markdown reports using any Ollama or LMStudio model—no cloud or API keys required.

View details
57
Repo Health
74
Technical
76
Dependency
Built with
Python 97%
Updated 2 weeks ago
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

22,931

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated today
Python
86%
Apache 2.0

PrivateGPT

AI Development

57,566

The open-source API layer that turns local LLMs into production private AI applications with full Claude API compatibility

View details
88
Repo Health
83
Technical
70
Dependency
Built with
Python 86%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers