Registry / serialization / mf2py
library2.0.1pypypi✓ verified 85d ago

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.

pip install mf2py
INSTALL
IMPORT
SIG · MF2PY
M
mf2py
serializationpythonv2.0.1
Install
2.6s avg
Import
1174ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.236s · 24.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 1.112s · 25MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from mf2py import parse
The primary convenience function for parsing HTML.
Parser
from mf2py import Parser
For advanced usage or when instantiating a parser object directly with specific options.

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"])
Debug
Known issues
breakingmf2py 2.0 officially dropped support for Python versions lower than 3.8. Attempting to install or run on older Python versions will result in errors.
fix
Upgrade your Python environment to 3.8 or higher. If unable, pin mf2py to a version < 2.0 (e.g., `mf2py<2.0`).
affects: >=2.0.0
breakingThe `img_with_alt` keyword argument for `parse()` and `Parser()` was removed in mf2py 2.0. Image `alt` text support is now enabled by default. Using this argument will raise an error.
fix
Remove `img_with_alt=True` or `img_with_alt=False` from your `mf2py.parse()` or `mf2py.Parser()` calls. The functionality is now on by default.
affects: >=2.0.0
breakingThe `dict_class` option for `Parser()` was removed and replaced with the standard `dict` in mf2py 2.0. Custom dictionary classes are no longer supported.
fix
Remove the `dict_class` argument from `mf2py.Parser()` instantiations. `mf2py` now consistently uses Python's built-in `dict`.
affects: >=2.0.0
gotchaWhen parsing HTML documents, especially from untrusted sources, be aware that passing a BeautifulSoup document to `mf2py` might modify the original BeautifulSoup object.
fix
If you need to preserve the original BeautifulSoup document, consider creating a deep copy before passing it to `mf2py.parse()` or `mf2py.Parser()`.
affects: All
Errors
Common errors & fixes
TypeError: Parser.__init__() got an unexpected keyword argument 'img_with_alt'
Attempting to use the `img_with_alt` argument which was removed in mf2py 2.0.
fix
Remove the `img_with_alt` parameter from `mf2py.parse()` or `mf2py.Parser()` calls. Image alt parsing is now enabled by default.
python: command not found
The `python` command is not in your system's PATH, or you intend to use `python3` specifically.
fix
Use `python3 -m pip install mf2py` or ensure `python` correctly points to your desired Python 3 interpreter.
ModuleNotFoundError: No module named 'mf2py'
The `mf2py` library is not installed in the current Python environment.
fix
Run `pip install mf2py` to install the library.
Upgrade
Version history
2.0.1latest on PyPI · released Dec 8, 2023
Audit
Dependencies
html5liboptionalDefault HTML parsing backend for robust HTML processing, especially with malformed HTML.
lxmloptionalAlternative, faster HTML parsing backend, can be used instead of html5lib.
Agent activity
4 hits · last 30 days
node
4
Resources
mf2py — pip install mf2py · libregistry