{"id":7407,"library":"mf2py","title":"mf2py: Microformats Parser","description":"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.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/microformats/mf2py","tags":["microformats","html","parser","web","indieweb","html5lib"],"install":[{"cmd":"pip install mf2py","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Default HTML parsing backend for robust HTML processing, especially with malformed HTML.","package":"html5lib","optional":true},{"reason":"Alternative, faster HTML parsing backend, can be used instead of html5lib.","package":"lxml","optional":true}],"imports":[{"note":"The primary convenience function for parsing HTML.","symbol":"parse","correct":"from mf2py import parse"},{"note":"For advanced usage or when instantiating a parser object directly with specific options.","symbol":"Parser","correct":"from mf2py import Parser"}],"quickstart":{"code":"import mf2py\n\nhtml_doc = \"\"\"\n<div class=\"h-entry\">\n    <h1 class=\"p-name\">My Awesome Post</h1>\n    <time class=\"dt-published\" datetime=\"2023-11-30T19:08:09\">November 30, 2023</time>\n    <a class=\"p-author h-card\" href=\"https://example.com/james\">James</a>\n    <img class=\"u-photo\" src=\"https://example.com/post-image.jpg\" alt=\"Post illustration\">\n</div>\n\"\"\"\n\nmf2_data = mf2py.parse(doc=html_doc)\n\nprint(mf2_data)\n\n# Example of parsing a URL (requires internet access)\n# from mf2py import parse\n# url_data = mf2py.parse(url=\"https://events.indieweb.org/\")\n# print(url_data[\"items\"][0][\"type\"])","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.8 or higher. If unable, pin mf2py to a version < 2.0 (e.g., `mf2py<2.0`).","message":"mf2py 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"The `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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove the `dict_class` argument from `mf2py.Parser()` instantiations. `mf2py` now consistently uses Python's built-in `dict`.","message":"The `dict_class` option for `Parser()` was removed and replaced with the standard `dict` in mf2py 2.0. Custom dictionary classes are no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If you need to preserve the original BeautifulSoup document, consider creating a deep copy before passing it to `mf2py.parse()` or `mf2py.Parser()`.","message":"When parsing HTML documents, especially from untrusted sources, be aware that passing a BeautifulSoup document to `mf2py` might modify the original BeautifulSoup object.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remove the `img_with_alt` parameter from `mf2py.parse()` or `mf2py.Parser()` calls. Image alt parsing is now enabled by default.","cause":"Attempting to use the `img_with_alt` argument which was removed in mf2py 2.0.","error":"TypeError: Parser.__init__() got an unexpected keyword argument 'img_with_alt'"},{"fix":"Use `python3 -m pip install mf2py` or ensure `python` correctly points to your desired Python 3 interpreter.","cause":"The `python` command is not in your system's PATH, or you intend to use `python3` specifically.","error":"python: command not found"},{"fix":"Run `pip install mf2py` to install the library.","cause":"The `mf2py` library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'mf2py'"}]}