Name | mf2py JSON |
Version |
2.0.1
JSON |
| download |
home_page | |
Summary | Microformats parser |
upload_time | 2023-12-08 03:41:59 |
maintainer | |
docs_url | None |
author | Tom Morris |
requires_python | >=3.8 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
![mf2py banner](https://microformats.github.io/mf2py/banner.png)
[![version](https://badge.fury.io/py/mf2py.svg?)](https://badge.fury.io/py/mf2py)
[![downloads](https://img.shields.io/pypi/dm/mf2py)](https://pypistats.org/packages/mf2py)
[![license](https://img.shields.io/pypi/l/mf2py?)](https://github.com/microformats/mf2py/blob/main/LICENSE)
[![python-version](https://img.shields.io/pypi/pyversions/mf2py)](https://badge.fury.io/py/mf2py)
## Welcome 👋
`mf2py` is a Python [microformats](https://microformats.org/wiki/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:
```bash
$ pip install mf2py
```
## Quickstart 🚀
Import the library:
```pycon
>>> import mf2py
```
### Parse an HTML Document from a file or string
```pycon
>>> 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.0',
'markup parser': 'html5lib'}}
```
```pycon
>>> 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
```pycon
>>> 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](https://microformats.org/wiki/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.
```pycon
>>> with open("test/examples/festivus.html") as fp:
... mf2parser = mf2py.Parser(doc=fp)
```
#### Filter by Microformat Type
```pycon
>>> 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
```pycon
>>> json = mf2parser.to_json()
>>> json_cards = mf2parser.to_json(filter_by_type="h-card")
```
## Breaking Changes in `mf2py` 2.0
- Image `alt` support is now on by default.
## Notes 📝
- If you pass a BeautifulSoup document it may be modified.
- A hosted version of `mf2py` is available at [python.microformats.io](https://python.microformats.io).
## Contributing 🛠️
We welcome contributions and bug reports via GitHub.
This project follows the [IndieWeb code of conduct](https://indieweb.org/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.
Raw data
{
"_id": null,
"home_page": "",
"name": "mf2py",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Tom Morris",
"author_email": "tom@tommorris.org",
"download_url": "https://files.pythonhosted.org/packages/f8/7d/bccfc42706cb24053e7897c33c14e79a8c9c69379d21edfca13ec93ed0ac/mf2py-2.0.1.tar.gz",
"platform": null,
"description": "![mf2py banner](https://microformats.github.io/mf2py/banner.png)\n\n[![version](https://badge.fury.io/py/mf2py.svg?)](https://badge.fury.io/py/mf2py)\n[![downloads](https://img.shields.io/pypi/dm/mf2py)](https://pypistats.org/packages/mf2py)\n[![license](https://img.shields.io/pypi/l/mf2py?)](https://github.com/microformats/mf2py/blob/main/LICENSE)\n[![python-version](https://img.shields.io/pypi/pyversions/mf2py)](https://badge.fury.io/py/mf2py)\n\n## Welcome \ud83d\udc4b\n\n`mf2py` is a Python [microformats](https://microformats.org/wiki/microformats) parser with full support for `microformats2`, backwards-compatible support for `microformats1` and experimental support for `metaformats`.\n\n## Installation \ud83d\udcbb\n\nTo install `mf2py` run the following command:\n\n```bash\n$ pip install mf2py\n\n```\n\n## Quickstart \ud83d\ude80\n\nImport the library:\n\n```pycon\n>>> import mf2py\n\n```\n\n### Parse an HTML Document from a file or string\n\n```pycon\n>>> with open(\"test/examples/eras.html\") as fp:\n... mf2json = mf2py.parse(doc=fp)\n>>> mf2json\n{'items': [{'type': ['h-entry'],\n 'properties': {'name': ['Excited for the Taylor Swift Eras Tour'],\n 'author': [{'type': ['h-card'],\n 'properties': {'name': ['James'],\n 'url': ['https://example.com/']},\n 'value': 'James',\n 'lang': 'en-us'}],\n 'published': ['2023-11-30T19:08:09'],\n 'featured': [{'value': 'https://example.com/eras.jpg',\n 'alt': 'Eras tour poster'}],\n 'content': [{'value': \"I can't decide which era is my favorite.\",\n 'lang': 'en-us',\n 'html': \"<p>I can't decide which era is my favorite.</p>\"}],\n 'category': ['music', 'Taylor Swift']},\n 'lang': 'en-us'}],\n 'rels': {'webmention': ['https://example.com/mentions']},\n 'rel-urls': {'https://example.com/mentions': {'text': '',\n 'rels': ['webmention']}},\n 'debug': {'description': 'mf2py - microformats2 parser for python',\n 'source': 'https://github.com/microformats/mf2py',\n 'version': '2.0.0',\n 'markup parser': 'html5lib'}}\n\n```\n\n```pycon\n>>> mf2json = mf2py.parse(doc=\"<a class=h-card href=https://example.com>James</a>\")\n>>> mf2json[\"items\"]\n[{'type': ['h-card'],\n 'properties': {'name': ['James'],\n 'url': ['https://example.com']}}]\n\n```\n\n### Parse an HTML Document from a URL\n\n```pycon\n>>> mf2json = mf2py.parse(url=\"https://events.indieweb.org\")\n>>> mf2json[\"items\"][0][\"type\"]\n['h-feed']\n>>> mf2json[\"items\"][0][\"children\"][0][\"type\"]\n['h-event']\n\n```\n\n## Experimental Options\n\nThe following options can be invoked via keyword arguments to `parse()` and `Parser()`.\n\n### `expose_dom`\n\nUse `expose_dom=True` to expose the DOM of embedded properties.\n\n### `metaformats`\n\nUse `metaformats=True` to include any [metaformats](https://microformats.org/wiki/metaformats)\nfound.\n\n### `filter_roots`\n\nUse `filter_roots=True` to filter known conflicting user names (e.g. Tailwind).\nOtherwise provide a custom list to filter instead.\n\n## Advanced Usage\n\n`parse` is a convenience function for `Parser`. More sophisticated behaviors are\navailable by invoking the parser object directly.\n\n```pycon\n>>> with open(\"test/examples/festivus.html\") as fp:\n... mf2parser = mf2py.Parser(doc=fp)\n\n```\n\n#### Filter by Microformat Type\n\n```pycon\n>>> mf2json = mf2parser.to_dict()\n>>> len(mf2json[\"items\"])\n7\n>>> len(mf2parser.to_dict(filter_by_type=\"h-card\"))\n3\n>>> len(mf2parser.to_dict(filter_by_type=\"h-entry\"))\n4\n\n```\n\n#### JSON Output\n\n```pycon\n>>> json = mf2parser.to_json()\n>>> json_cards = mf2parser.to_json(filter_by_type=\"h-card\")\n\n```\n\n## Breaking Changes in `mf2py` 2.0\n\n- Image `alt` support is now on by default.\n\n## Notes \ud83d\udcdd\n\n- If you pass a BeautifulSoup document it may be modified.\n- A hosted version of `mf2py` is available at [python.microformats.io](https://python.microformats.io).\n\n## Contributing \ud83d\udee0\ufe0f\n\nWe welcome contributions and bug reports via GitHub.\n\nThis project follows the [IndieWeb code of conduct](https://indieweb.org/code-of-conduct). Please be respectful of other contributors and forge a spirit of positive co-operation without discrimination or disrespect.\n\n## License \ud83e\uddd1\u200d\u2696\ufe0f\n\n`mf2py` is licensed under an MIT License.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Microformats parser",
"version": "2.0.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8e88b1d83c9e71cbdaefcec38ea350d2bd6360a9d1e030b090ad4b0fcc421ca1",
"md5": "0c4d2d5a536719f60454ea5373db319e",
"sha256": "092806e17f1a93db4aafa5e8d3c4124b5e42cd89027e2db48a5248ef4eabde03"
},
"downloads": -1,
"filename": "mf2py-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c4d2d5a536719f60454ea5373db319e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 25767,
"upload_time": "2023-12-08T03:41:58",
"upload_time_iso_8601": "2023-12-08T03:41:58.443859Z",
"url": "https://files.pythonhosted.org/packages/8e/88/b1d83c9e71cbdaefcec38ea350d2bd6360a9d1e030b090ad4b0fcc421ca1/mf2py-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f87dbccfc42706cb24053e7897c33c14e79a8c9c69379d21edfca13ec93ed0ac",
"md5": "178614c416a1e0097bed573c56073e2e",
"sha256": "1380924633413b8d72e704b5c86b4382c4b1371699edecc907b01cd21138d7cd"
},
"downloads": -1,
"filename": "mf2py-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "178614c416a1e0097bed573c56073e2e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 21843,
"upload_time": "2023-12-08T03:41:59",
"upload_time_iso_8601": "2023-12-08T03:41:59.755700Z",
"url": "https://files.pythonhosted.org/packages/f8/7d/bccfc42706cb24053e7897c33c14e79a8c9c69379d21edfca13ec93ed0ac/mf2py-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-08 03:41:59",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "mf2py"
}