Skip to main content

mwextract

Convert a MediaWiki XML dump (as shipped by Fandom/Wikia and other MediaWiki sites) into clean, structured Markdown, JSON, or XML — one command, no pandoc, no other binaries.

It uses only the Wikimedia parsing stack:

  • mwxml streams pages out of the dump (memory-safe, namespace-aware).
  • mwparserfromhell parses wikitext: infobox/template fields become metadata, and the article body is rendered to clean Markdown.
  • py7zr extracts the .7z archive the dump usually comes in.

Install

uv add mwextract
# or
pip install mwextract

Get a dump

mwextract does not download anything — you fetch the dump yourself. Fandom wikis expose current-page dumps under a URL like:

https://s3.amazonaws.com/wikia_xml_dumps/<x>/<xx>/<wiki>_pages_current.xml.7z

For example, the Game of Thrones wiki: https://s3.amazonaws.com/wikia_xml_dumps/g/ga/gameofthrones_pages_current.xml.7z

Download the .7z and point mwextract at it.

Use it from Python

import mwextract

result = mwextract.convert(
    "gameofthrones_pages_current.xml.7z",   # .7z, .xml, or .xml.bz2
    "out/",                                  # output directory
    base_url="https://gameofthrones.fandom.com/wiki/",  # optional
    fmt="md",                                # "md" | "json" | "xml"
    layout="combined",                       # "combined" | "per-file"
)

print(result.pages, "pages ->", result.outputs)

convert() extracts the archive to a temporary directory (removed afterwards), streams every main-namespace, non-redirect article, and writes the chosen format.

Use it from the command line

mwextract gameofthrones_pages_current.xml.7z out/ \
  --base-url https://gameofthrones.fandom.com/wiki/ \
  --format md \
  --layout combined
usage: mwextract [-h] [-b BASE_URL] [-f {md,json,xml}]
                 [-l {combined,per-file}] [-q] [-V]
                 dump output_dir
Option Default Meaning
dump — Path to the dump: .7z, .xml, or .xml.bz2.
output_dir — Directory to write into (created if missing).
-b, --base-url (none) Wiki URL prefix; when set, each page gets a url.
-f, --format md md, json, or xml.
-l, --layout combined combined (one file) or per-file (one per article).
-q, --quiet off Only warnings/errors.

Output

Layouts

  • combined (default) — a single file for the whole corpus: corpus.md, corpus.json (a JSON array), or corpus.xml (<pages><page>…</page></pages>).
  • per-file — one file per article, named after the title: Daenerys_Targaryen.md, .json, or .xml.

Both layouts are written incrementally as pages stream in, so memory stays flat no matter how large the dump is.

Formats

Markdown — YAML front-matter (title, url, infobox fields) + an optional summary line + the rendered body:

---
title: "Jon Snow"
url: https://gameofthrones.fandom.com/wiki/Jon_Snow
house: "Stark"
allegiance: "Night's Watch"
---

# Jon Snow

> **House:** Stark · **Allegiance:** Night's Watch

Jon Snow is the illegitimate son of ...

JSON — the same content, structured:

{
  "title": "Jon Snow",
  "url": "https://gameofthrones.fandom.com/wiki/Jon_Snow",
  "metadata": { "house": "Stark", "allegiance": "Night's Watch" },
  "body": "Jon Snow is the illegitimate son of ..."
}

XML — the same content as elements:

<page>
  <title>Jon Snow</title>
  <url>https://gameofthrones.fandom.com/wiki/Jon_Snow</url>
  <metadata>
    <field name="house">Stark</field>
    <field name="allegiance">Night's Watch</field>
  </metadata>
  <body>Jon Snow is the illegitimate son of ...</body>
</page>

body is the rendered Markdown body only — the structured metadata/url carry everything the Markdown front-matter would, so nothing is duplicated.

What gets kept / dropped

  • Kept: main-namespace articles, section hierarchy, bold/italic, list items, wikilink and external-link visible text, infobox fields (as metadata).
  • Dropped: redirects and non-article namespaces, file/image/category/media links, citation footnotes (<ref>), templates (after their infobox fields are extracted), and comments.

License

MIT © Aditya Parab

Metadata

Release files for mwextract 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mwextract 0.1.0
File Size Uploaded
mwextract-0.1.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mwextract 0.1.0
File Interpreter ABI Platform
mwextract-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / mwextract-0.1.0.tar.gz

Download URL mwextract-0.1.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
21f3850cb61f228c4303b7c0fa82d53016586c933e33917175a9a5b6fd15b0f5
BLAKE2b-256 checksum
How to use checksums
cc4ae4ec30a238fb65e219ab60039ee8e9810fc251f190af76604b7111c66606
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mwextract-0.1.0-py3-none-any.whl

Download URL mwextract-0.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14f54b342be61de55773db8f94268ad6c9d78c1cf9883e2464b9f397f3e256db
BLAKE2b-256 checksum
How to use checksums
8cc1609482e447c159b1139c71933381f30cf58f1234b22cf9ee658a38e82917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page