Skip to main content

wikiq

wikiq converts MediaWiki XML database dumps—the "history" dumps that include every revision of every page—into tabular datasets for research. It is a command line program that produces one row per revision with metadata such as the page, namespace, timestamp, editor, text size, and revert status, plus a range of optional computed columns.

Installation

wikiq requires Python 3.11 or later. Install it from PyPI:

pip install wikiq

Wikimedia dumps are usually compressed as 7z (most common), gz, or bz2. wikiq reads these by running your system's decompression tools, so it depends on 7za, zcat, and bzcat for those respective formats. On Debian or Ubuntu, apt install 7zip provides 7za; the others are standard.

That is everything most uses need, and none of it requires a compiler. Two further features carry heavier dependencies, so they are kept out of the base install.

Diffs and wikidiff2 persistence

--diff and -p wikidiff2 need pywikidiff2, a Python binding for MediaWiki's wikidiff2 diff engine. It is not on PyPI and compiles a C++ extension, so it needs a C++ compiler and libthai:

pip install 'pywikidiff2 @ git+https://gitea.communitydata.science/groceryheist/pywikidiff2.git'

The other persistence methods, including the default -p sequence, do not need it.

Legacy persistence

-p legacy needs mediawiki-utilities, which is only useful for reproducing results from older research projects:

pip install 'wikiq[legacy]'

wikiq tells you which of these to install if you use an option that needs one.

Usage

wikiq dump.xml.7z -o output/

Each output row describes one revision. The output format follows the -o argument: a path ending in .jsonl produces JSON Lines, anything else produces tab-separated values. With no dump file argument, wikiq reads XML on stdin and writes to stdout.

The title and namespace columns are page-level identity values as of the time of export: a moved page's entire history carries its final title, and namespace derives from that title. Redirect status, by contrast, is determined per revision from each revision's own text: the revision_is_redirect and revision_redirect_target columns record whether a revision's text begins with a redirect directive and where it points. #REDIRECT is recognized on every wiki; wikis that also use a localized keyword can add it with --redirect-aliases (for example, --redirect-aliases OMDIRIGERING for Swedish wikis).

The most commonly useful options (wikiq --help describes them all):

  • -n ID limits output to a namespace, and can be given more than once. -rr N sets how many prior edits are checked when detecting reverts.
  • --collapse-user collapses each sequence of consecutive edits by the same user into a single row, which can address problems with text persistence measures.
  • -p [METHOD] computes content persistence measures for each revision: persistent token revisions, tokens added, and tokens removed. The available methods are sequence (the default), segment (robust to content moves but slower), wikidiff2 (like segment, using the wikidiff2 diff engine), and legacy (the behavior of older research projects). Persistence is the slowest thing wikiq computes.
  • -d outputs a structured diff for each revision; -t outputs the full revision text.
  • --external-links, --citations, --wikilinks, --templates, and --headings parse each revision's wikitext and add a column with the extracted elements.
  • -RP REGEX -RPl LABEL searches revision text for a regular expression and reports the matches in a column named by the label; repeat the pair for multiple patterns. -CP/-CPl do the same for edit summaries. Adding -RPc or -CPc reports the number of matches instead of the matched text.
  • --resume continues an interrupted run from the last complete line of an existing JSONL output file. Combined with --time-limit HOURS, this supports processing very large dumps in bounded chunks.
  • --print-schema prints a Spark-compatible JSON schema for the configured output and exits.

Tests

From a clone of the repository:

git clone https://gitea.communitydata.science/collective/wikiq.git
cd wikiq
pip install -e '.[dev]'
pytest test/

Run the suite from the root—some tests open fixture files by paths relative to it. The full suite processes several real dumps from test/dumps/; expected outputs live in test/baseline_output/.

Tests covering --diff, -p wikidiff2, and -p legacy skip when their optional dependency is absent, so a base install reports skips rather than failures.

Authors

wikiq is written and maintained by members of the Community Data Science Collective. Contributors include Benjamin Mako Hill, Nathan TeBlunthuis, Will Beason, Sohyeon Hwang, and Kaylea Champion. It builds on earlier versions of the tool written in Python and in C++ by Benjamin Mako Hill.

License

wikiq is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See COPYING for the full text.

Metadata

Release files for wikiq 0.3.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 wikiq 0.3.0
File Size Uploaded Provenance Actions
wikiq-0.3.0.tar.gz 41.2 kB Without provenance Details for wikiq-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 84.9 kB

Release files / wikiq-0.3.0.tar.gz

Download URL wikiq-0.3.0.tar.gz
Size 41.2 kB
Tags Source
SHA-256 checksum
How to use checksums
966c589fccd82de6ca7e91bbeb6e675ec17137321a744b5347e7e0c88b936ba2
BLAKE2b-256 checksum
How to use checksums
8aa3ef6bf592aee65bd7a33d2f8f9a068c44270914040ca3d2dd940452cf62ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / wikiq-0.3.0-py3-none-any.whl

Download URL wikiq-0.3.0-py3-none-any.whl
Size 43.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fe436f6b847db5c31be2794f0233064ca5aaa1931924eb20d7cfb6bfe2cb638
BLAKE2b-256 checksum
How to use checksums
2a865379b22e97b615948a345f045a1b919dff6b8b47891daf14b5509bb55a77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for wikiq 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

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