Python Microformats2 parser
Project description
Welcome 👋
mf2py is a full-featured microformats2 (mf2) parser implemented in Python.
mf2py implements the full mf2 specification, including backward compatibility with microformats1.
Installation 💻
To install mf2py, run the following command:
pip install mf2py
Quickstart 🚀
Import the parser using:
import mf2py
Parse a File
Parse a file containing HTML:
with open('file/content.html','r') as file:
obj = mf2py.parse(doc=file)
Parse a String
Parse string containing HTML content:
content = '<article class="h-entry"><h1 class="p-name">Hello</h1></article>'
obj = mf2py.parse(doc=content)
Parse a HTML Document Retrieved from a URL
Parse content from a URL:
obj = mf2py.parse(url="http://tommorris.org/")
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.
Format Options
Retrieve parsed microformats as a Python dictionary or JSON string:
p = mf2py.Parser(...)
p.to_dict() # returns a python dictionary
p.to_json() # returns a JSON string
Filter by Microformat Type
Filter by microformat type:
p.to_dict(filter_by_type="h-entry")
p.to_json(filter_by_type="h-entry")
Experimental Features 🧪
- Pass the optional argument
img_with_alt=Trueto either theParserobject or to theparsemethod to enable parsing of thealtattribute of<img>tags according to issue: image alt text is lost during parsing. By default this isFalseto be backwards compatible.
FAQs ❓
- I passed
mf2py.parse()a BeautifulSoup document, and it got modified!
Yes, mf2py currently does that. We're working on preventing it! Hopefully soon.
Testing Environments 🌐
A hosted live version of mf2py can be found at python.microformats.io.
Contributing 🛠️
We welcome contributions and bug reports via Github, and on the microformats wiki.
We 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.
License 🧑⚖️
mf2py is licensed under an MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mf2py-1.1.3.tar.gz.
File metadata
- Download URL: mf2py-1.1.3.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4241e91ed4b644dd666d9fbd2557ed86e5bb7399c196026f7b0a1f413b33f59f
|
|
| MD5 |
4cea15beb0b18619dee15b7489ffe9d1
|
|
| BLAKE2b-256 |
638b0668095232cbb3bb01c4492fbc9e5578ceafdd85a6180bc4ed1703908c29
|
File details
Details for the file mf2py-1.1.3-py3-none-any.whl.
File metadata
- Download URL: mf2py-1.1.3-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f9e2c147beadd56f8839644124c7d141d96e879319b9f50d02826c88766bf4d
|
|
| MD5 |
e2b4b8dfe2720cb45c6245c9e335de8f
|
|
| BLAKE2b-256 |
86e9feebadcc2ffd04f13b4d261c07ce0a89b562e66984946f5bac6f2cf46703
|