mf2py: Microformats Parser

2.0.1 · active · verified Thu Apr 16

mf2py is a Python library for parsing Microformats data from HTML documents. It provides full support for microformats2, offers backwards-compatible support for microformats1, and includes experimental support for metaformats. The library is actively maintained, with version 2.0.1 being the latest release, and is part of the broader IndieWeb ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse an HTML string containing microformats2 markup using `mf2py.parse()`. It returns a dictionary representing the microformats found. You can also parse directly from a URL.

import mf2py

html_doc = """
<div class="h-entry">
    <h1 class="p-name">My Awesome Post</h1>
    <time class="dt-published" datetime="2023-11-30T19:08:09">November 30, 2023</time>
    <a class="p-author h-card" href="https://example.com/james">James</a>
    <img class="u-photo" src="https://example.com/post-image.jpg" alt="Post illustration">
</div>
"""

mf2_data = mf2py.parse(doc=html_doc)

print(mf2_data)

# Example of parsing a URL (requires internet access)
# from mf2py import parse
# url_data = mf2py.parse(url="https://events.indieweb.org/")
# print(url_data["items"][0]["type"])

view raw JSON →