python-markdownify: one function, a BeautifulSoup walk, and a long list of output switches
Convert HTML to Markdown
At a glance
- What is it?
- markdownify turns an HTML string into Markdown through a single markdownify function and about two dozen keyword options. This piece covers what each option changes, where the defaults surprise, and what the library leaves undone.
- Who is it for?
- Pick markdownify when you already have HTML strings or BeautifulSoup objects in a Python script and want Markdown out with a few tuned output rules. Skip it if you need to read PDFs, Word files or anything that is not HTML, because the repository documents none of that.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 7 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- matthewwithanm/python-markdownify2,262 ★ · +8
| Repository | 2026-10-11 | 2026-11-25 |
|---|---|---|
| matthewwithanm/python-markdownify | 2.3k | 2.3k |
8 Stars in the last 45 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
One import, one call, and two lines of dependency
Installation is a single command:
pip install markdownifyThe package declares two runtime dependencies in pyproject.toml, beautifulsoup4>=4.9,<5 and six>=1.15,<2. That pin matters in practice: BeautifulSoup does the parsing, and markdownify only walks the resulting tree and emits Markdown text. Anything BeautifulSoup cannot parse sensibly will not come out better on the Markdown side.
The whole public surface in the README's first example is one function:
from markdownify import markdownify as md
md('<b>Yay</b> <a href="http://github.com">GitHub</a>') # > '**Yay** [GitHub](http://github.com)'Bold becomes double asterisks and an anchor becomes an inline link. Everything else in the project is a keyword argument to that call or a setting on a subclass.
strip and convert are mutually exclusive filters
Two options decide which tags take part at all. strip takes a list of tags to remove, and convert takes a list of tags to keep converting. The README states that neither can be combined with the other, so a script that needs both behaviours has to pick one list and express the other by omission.
The README shows each with the same input. With strip=['a'] the link text survives and the URL does not:
from markdownify import markdownify as md
md('<b>Yay</b> <a href="http://github.com">GitHub</a>', strip=['a']) # > '**Yay** GitHub'With convert=['b'] only bold is translated and the anchor is flattened to its text, which produces the same output string. The consequence for a scraper is that convert acts as an allowlist, so any tag you forget to name loses its Markdown form silently.
Setext headings are the default, and bullets rotate by depth
heading_style accepts ATX, ATX_CLOSED, SETEXT and UNDERLINED, where UNDERLINED is an alias for SETEXT. The default is UNDERLINED. If your downstream renderer or diff tooling expects lines starting with hash marks, you must set heading_style to ATX yourself, because converting a page without the option gives underlined headings.
Bullets follow a similar pattern. The bullets option takes a string, list or tuple, and its default is '*+-'. With more than one item, the bullet character alternates with nesting level. Pass a single item and it is used at every depth. Output from nested lists therefore changes markers from one level to the next unless you override that.
strong_em_symbol chooses between ASTERISK (the default) and UNDERSCORE for bold and italic, and newline_style chooses SPACES (two spaces plus newline, the default) or BACKSLASH for a converted br tag.
Escaping: asterisks and underscores on, everything else off
Three options control backslash escaping in text. escape_asterisks and escape_underscores both default to True, so a literal * in the source becomes \* in the output, and the same for underscores. Setting them to False leaves those characters alone, which reads better in plain text but can let stray characters be interpreted as emphasis by the next Markdown renderer.
escape_misc defaults to False. When set to True it escapes miscellaneous punctuation characters that sometimes have Markdown significance. The README does not list which characters, so test with your own content before relying on it.
This split means the defaults protect against the two most common accidental emphasis markers and ignore the rest. A page full of text such as list-like lines starting with a number and period is not protected unless you opt in.
Code fences get a language only if you tell the converter how
code_language sets one language for every pre block. That suits a documentation page where all samples are Python, and the README says the default is an empty string.
When the HTML carries the language on the tag, code_language_callback does the extraction. The callback receives a BeautifulSoup element and returns a string or None. The README gives this example, which uses the first class name:
def callback(el):
return el['class'][0] if el.has_attr('class') else NoneThe default is None, so without a callback or a fixed language, fenced blocks carry no language tag. strip_pre then decides what happens to blank lines at the edges of a pre block: STRIP removes all of them (the default), STRIP_ONE removes one, and None leaves them.
Images in headings and tables collapse to alt text
Images inside headlines or table cells are converted to their alt text. That default drops the image reference, so a table of icons or a heading with a logo loses it. keep_inline_images_in takes a list of parent tags, for example ['td'], where inline images should stay as Markdown images. Its default is an empty list.
Tables raise a second question. A table with no thead or th has no header row, and Markdown tables require one. table_infer_header set to True promotes the first body row to the header. At the default False, the header row is left empty. If your sources are spreadsheet exports rendered to bare tr and td markup, this option is the difference between a usable table and one with a blank first line.
Links have their own switches. autolinks, default True, uses the automatic link style when an anchor's text equals its href, and default_title, default False, copies the href into the title when no title is given.
Wrapping, document trimming and parser choice
wrap defaults to False. Set it to True and paragraphs wrap at wrap_width, which defaults to 80. The README advises combining wrapping with newline_style=BACKSLASH to keep line breaks inside paragraphs, and notes that a wrap_width of None reflows to unlimited line length.
strip_document trims separation newlines from the final output. Its values are LSTRIP, RSTRIP, STRIP (the default) and None. sub_symbol and sup_symbol default to empty strings because sub and superscript Markdown is non-standard. Set them to ~ and ^ to get ~sub~ and ^sup^, or to a value beginning with < and ending with > to emit raw HTML tags.
bs4_options passes configuration to the BeautifulSoup object. A string or list such as lxml or html5lib is treated as the features argument, which selects a parser. A dictionary such as {"from_encoding": "iso-8859-8"} is passed as full constructor kwargs. Parser choice is therefore yours, and the package depends only on beautifulsoup4.
Release cadence, Python support and what the repository does not cover
The default branch is develop, the license is MIT, and the repository is not archived. The last push was 2026-06-30, the same day release 1.2.3 was published. Earlier releases are 1.2.2 on 2025-11-16 and 1.2.0 on 2025-08-09.
The classifiers in pyproject.toml list Python 2.5, 2.6, 2.7, 3.6, 3.7 and 3.8, which is an old list next to a 2026 release, and no newer Python versions are named there. The same file declares a console script, markdownify = "markdownify.main:main", though the README text provided here does not document its arguments.
The repository handles HTML only. A search for converting PDF files with markdownify finds nothing in the README or pyproject.toml, and the README does not compare itself to other converters. Options may be passed as kwargs to the markdownify function, or as a nested Options class in MarkdownConverter subclasses, which is the route when you want custom rules without repeating arguments.
Editorial conclusion
Pick markdownify when you already have HTML strings or BeautifulSoup objects in a Python script and want Markdown out with a few tuned output rules. Skip it if you need to read PDFs, Word files or anything that is not HTML, because the repository documents none of that. Before adopting it, run your own pages through it with heading_style, bullets and the escape options set, and check how your tables and images come out, since those are the places the defaults make choices for you.
Frequently asked questions
How do I install python-markdownify?
Run pip install markdownify. The package depends on beautifulsoup4 (>=4.9,<5) and six (>=1.15,<2), both declared in pyproject.toml.
Can python-markdownify convert only some HTML tags?
Yes. The strip option removes listed tags and the convert option converts only listed tags. They cannot be used together.
What heading style does python-markdownify produce by default?
The default heading_style is UNDERLINED, an alias for SETEXT. Set heading_style to ATX or ATX_CLOSED for hash-mark headings.
Does python-markdownify escape asterisks and underscores?
By default it does. escape_asterisks and escape_underscores are both True. Set them to False to leave those characters unescaped.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/matthewwithanm-python-markdownify)Star history chart for your README
[](https://hysenlabs.com/projects/matthewwithanm-python-markdownify)Was this useful?