wikitextparser

raw JSON →
0.56.4 verified Fri May 01 auth: no python

A simple parsing tool for MediaWiki's wikitext markup. Current version: 0.56.4. Releases follow no fixed cadence.

pip install wikitextparser
error ModuleNotFoundError: No module named 'wikitextparser'
cause The package is not installed.
fix
Run pip install wikitextparser.
error AttributeError: 'WikiText' object has no attribute 'templates'
cause Using an outdated version where attributes differed.
fix
Upgrade to latest version: pip install --upgrade wikitextparser.
gotcha The library returns an empty list for `templates` if no template syntax is present. New users often expect `None` instead.
fix Check `len(result.templates) > 0` to see if any templates exist.
deprecated The `remove_comments` method was deprecated in v0.55 in favor of the `strip_comments` parameter
fix Use `parse(text, strip_comments=True)` instead of calling `.remove_comments()`.
gotcha Wikitext with unclosed tags may raise a `ParseError`. The parser expects valid markup.
fix Ensure wikitext is well-formed or catch `wikitextparser.ParseError`.

Parse a simple wikitext string and access wikilinks and templates.

import wikitextparser as wtp

wikitext = """[[Link]]
== Heading ==
Some ''italic'' text."""
parsed = wtp.parse(wikitext)
print(parsed.templates)  # empty list
print(parsed.wikilinks)  # [WikiLink('Link')]