mwparserfromhell is used by and originally developed for EarwigBot; Page objects have a parse() method that essentially calls mwparserfromhell.parse() on get().

If you’re using Pywikibot, your code might look like this:

import mwparserfromhell import pywikibot

def parse(title):
site = pywikibot.Site() page = pywikibot.Page(site, title) text = page.get() return mwparserfromhell.parse(text)

If you’re not using a library, you can parse any page with the following Python 3 code (using the API and the requests library):

import mwparserfromhell import requests


def parse(title):
params = {
“action”: “query”, “prop”: “revisions”, “rvprop”: “content”, “rvslots”: “main”, “rvlimit”: 1, “titles”: title, “format”: “json”, “formatversion”: “2”,

} headers = {“User-Agent”: “My-Bot-Name/1.0”} req = requests.get(API_URL, headers=headers, params=params) res = req.json() revision = res[“query”][“pages”][0][“revisions”][0] text = revision[“slots”][“main”][“content”] return mwparserfromhell.parse(text)