Welcome 👋
mf2py is a Python microformats parser with full support for microformats2, backwards-compatible support for microformats1 and experimental support for metaformats.
Installation 💻
To install mf2py run the following command:
$ pip install mf2py
Quickstart 🚀
Import the library:
>>> import mf2py
Parse an HTML Document from a file or string
>>> with open("test/examples/eras.html") as fp:
... mf2json = mf2py.parse(doc=fp)
>>> mf2json
{'items': [{'type': ['h-entry'],
'properties': {'name': ['Excited for the Taylor Swift Eras Tour'],
'author': [{'type': ['h-card'],
'properties': {'name': ['James'],
'url': ['https://example.com/']},
'value': 'James',
'lang': 'en-us'}],
'published': ['2023-11-30T19:08:09'],
'featured': [{'value': 'https://example.com/eras.jpg',
'alt': 'Eras tour poster'}],
'content': [{'value': "I can't decide which era is my favorite.",
'lang': 'en-us',
'html': "<p>I can't decide which era is my favorite.</p>"}],
'category': ['music', 'Taylor Swift']},
'lang': 'en-us'}],
'rels': {'webmention': ['https://example.com/mentions']},
'rel-urls': {'https://example.com/mentions': {'text': '',
'rels': ['webmention']}},
'debug': {'description': 'mf2py - microformats2 parser for python',
'source': 'https://github.com/microformats/mf2py',
'version': '2.0.2',
'markup parser': 'html5lib'}}
>>> mf2json = mf2py.parse(doc="<a class=h-card href=https://example.com>James</a>")
>>> mf2json["items"]
[{'type': ['h-card'],
'properties': {'name': ['James'],
'url': ['https://example.com']}}]
Parse an HTML Document from a URL
>>> mf2json = mf2py.parse(url="https://events.indieweb.org")
>>> mf2json["items"][0]["type"]
['h-feed']
>>> mf2json["items"][0]["children"][0]["type"]
['h-event']
Experimental Options
The following options can be invoked via keyword arguments to parse() and Parser().
expose_dom
Use expose_dom=True to expose the DOM of embedded properties.
metaformats
Use metaformats=True to include any metaformats
found.
filter_roots
Use filter_roots=True to filter known conflicting user names (e.g. Tailwind).
Otherwise provide a custom list to filter instead.
Advanced Usage
parse is a convenience function for Parser. More sophisticated behaviors are
available by invoking the parser object directly.
>>> with open("test/examples/festivus.html") as fp:
... mf2parser = mf2py.Parser(doc=fp)
Filter by Microformat Type
>>> mf2json = mf2parser.to_dict()
>>> len(mf2json["items"])
7
>>> len(mf2parser.to_dict(filter_by_type="h-card"))
3
>>> len(mf2parser.to_dict(filter_by_type="h-entry"))
4
JSON Output
>>> json = mf2parser.to_json()
>>> json_cards = mf2parser.to_json(filter_by_type="h-card")
Breaking Changes in mf2py 2.0
- Image
altsupport is now on by default.
Notes 📝
- If you pass a BeautifulSoup document it may be modified.
- A hosted version of
mf2pyis available at python.microformats.io.
Contributing 🛠️
We welcome contributions and bug reports via GitHub.
This project follows the IndieWeb code of conduct. Please be respectful of other contributors and forge a spirit of positive co-operation without discrimination or disrespect.
License 🧑⚖️
mf2py is licensed under an MIT License.
Metadata
Release files for mf2py 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mf2py-2.0.2.tar.gz | 21.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mf2py-2.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.6 kB
Release files / mf2py-2.0.2.tar.gz
| Download URL | mf2py-2.0.2.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2851972e514673add74cd2f2898453a50945029ea4a7d32cfdbf231985282ee9
|
|
BLAKE2b-256 checksum How to use checksums |
3939d6c8c3fb8243c85d24f14307c4345b6608135027816db598ff099f0c5ada
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.1 Linux/5.10.0-23-amd64
|
Release files / mf2py-2.0.2-py3-none-any.whl
| Download URL | mf2py-2.0.2-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
edc5b433e970e5e9a480e112b2ca5b203299b7c918127501fcb823b5c8fbb905
|
|
BLAKE2b-256 checksum How to use checksums |
5ab9487b9ac9541721f02886b225ac15bac3e291b7a59f30dd36502f630cc4d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.11.1 Linux/5.10.0-23-amd64
|
Security for mf2py 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.