Skip to content
Microformats2 parser written in Python
Python HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Merge pull request #139 from sknebel-forks/fix-138 Dec 17, 2018
.gitignore whitespace handling: don't collapse whitespace between tags Jul 27, 2018
.gitmodules Add backcompat for wordpress, blogger (#74) Aug 23, 2016
.travis.yml drop 2.6 from tests since html5lib dropped support. add upto 3.6 vers… Mar 4, 2018
AUTHORS release v1.1.2 Aug 8, 2018
Makefile starting this off Nov 6, 2013 Revert "make a deepcopy of BS document to avoid making changes to ori… Jul 31, 2018 PEP8 fixes Jun 17, 2016
requirements.txt [Security] Bump requests from 2.19.1 to 2.21.0 Dec 11, 2018


Build Status

Can I Use Python 3?

Python parser for microformats 2.

Current status: Full-featured and mostly stable. Implements the full mf2 spec, including backward compatibility with microformats1.

Documentation, code tidying and so on is rather lacking.

License: MIT


pip install mf2py


Import the parser using

import mf2py

Parse a file containing the content

with open('file/content.html','r') as file:
    obj = mf2py.parse(doc=file)

Parse string containing content

content = '<article class="h-entry"><h1 class="p-name">Hello</h1></article>'
obj = mf2py.parse(doc=content)

Parse content from a URL

obj = mf2py.parse(url="")

parse is a convenience method that actually delegates to mf2py.Parser to do the real work. More sophisticated behaviors are available by invoking the object directly.

Get parsed microformat in a variety of formats

p = mf2py.Parser(...)
p.to_dict()  # returns a python dictionary
p.to_json()  # returns a JSON string

Filter by microformat type


Experimental features

  • pass the optional argument img_with_alt=True to either the Parser object or to the parse method to enable parsing of the alt attribute of <img> tags according to issue: image alt text is lost during parsing. By default this is False to be backwards compatible.


  • I passed mf2py.parse() a BeautifulSoup document, and it got modified!

Yes, mf2py currently does that. We're working on preventing it! Hopefully soon.


A basic web interface for mf2py and mf2util is available at mf2py-web.

A hosted live version can be found at


We welcome contributions and bug reports via Github, and on the microformats wiki.

We try to follow the IndieWebCamp code of conduct. Please be respectful of other contributors, and forge a spirit of positive co-operation without discrimination or disrespect.

You can’t perform that action at this time.