Skip to main content

Wiki dump extractor

A python library to extract and analyze pages from a wiki dump.

This library is used in particular in the Landnotes project to extract and analyze pages from the Wikipedia dump.

The project is hosted on GitHub an the HTML documentation is available here.

Scope

Make the wikipedia dumps easier to work with:

  • Extract pages from a wiki dump
  • Be easy to install and run
  • Be fast (can iterate over 50,000 pages / secong using Avro)
  • Be memory efficient
  • Allow for batch processing and parallel processing

Provide utilities for page analysis:

  • Date parsing
  • Section extraction
  • Text cleaning
  • and more.

Usage

To simply iterate over the pages in the dump:

from wiki_dump_extractor import WikiDumpExtractor

dump_file = "enwiki-20220301-pages-articles-multistream.xml.bz2"
extractor = WikiDumpExtractor(file_path=dump_file)
for page in extractor.iter_pages(limit=1000):
    print(page.title)

To extract the pages by batches (here we save the pages separate CSV files):

from wiki_dump_extractor import WikiDumpExtractor

dump_file = "enwiki-20220301-pages-articles-multistream.xml.bz2"
extractor = WikiDumpExtractor(file_path=dump_file)
batches = extractor.iter_page_batches(batch_size=1000, limit=10)
for i, batch in enumerate(batches):
    df = pandas.DataFrame([page.to_dict() for page in batch])
    df.to_csv(f"batch_{i}.csv")

Converting the dump to Avro

There are many reasons why you might want to convert the dump to Avro. The original xml.bz2 dump is 22Gb but very slow to read from (250/s), the uncompressed dump is 107Gb, relatively fast to read (this library uses lxml which reads thousands of pages per second), however 50% of the pages in there are empty redirect pages.

The following code converts the batch to a 28G avro dump that only contains the 12 million real pages, stores redirects in a fast LMDB database, and creates an index for quick page lookups. The operation takes ~40 minutes depending on your machine.

from wiki_dump_extractor import WikiXmlDumpExtractor

file_path = "enwiki-20250201-pages-articles-multistream.xml"
extractor = WikiXmlDumpExtractor(file_path=file_path)
ignored_fields = ["timestamp", "page_id", "revision_id", "redirect_title"]
extractor.extract_pages_to_avro(
    output_file="wiki_dump.avro",
    redirects_db_path="redirects.lmdb",  # LMDB database for fast redirect lookups
    ignored_fields=ignored_fields,
)

Then index the pages for fast lookups:

from wiki_dump_extractor import WikiAvroDumpExtractor

extractor = WikiAvroDumpExtractor(file_path="wiki_dump.avro")
extractor.index_pages(page_index_db="page_index.lmdb")

Later on, read the Avro file and use redirects and index as follows (reads the 12 million pages in ~3-4 minutes depending on your machine):

from wiki_dump_extractor import WikiAvroDumpExtractor

# Create extractor
extractor = WikiAvroDumpExtractor(
    file_path="wiki_dump.avro",
    index_dir="page_index.lmdb"  # Use the index for faster lookups
)

# Get pages with automatic redirect resolution
pages = extractor.get_page_batch_by_title(
    ["Page Title 1", "Page Title 2"]
)

Installation

pip install wiki-dump-extractor

Or from the source in development mode:

pip install -e .

To use the LLM-specific module (that would be mostly if you are on a project like Landnotes), use

pip install wiki-dump-extractor[llm]

Or locally:

pip install -e ".[llm]"

To install with tests, use pip install -e ".[dev]" then run the tests with pytest in the root directory.

Requirements for running the LLM utils

# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

Release files for wiki-dump-extractor 0.1.2

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

Source distribution (sdist)

Source distribution for wiki-dump-extractor 0.1.2
File Size Uploaded
wiki_dump_extractor-0.1.2.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wiki-dump-extractor 0.1.2
File Interpreter ABI Platform
wiki_dump_extractor-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 54.4 kB

Release files / wiki_dump_extractor-0.1.2.tar.gz

Download URL wiki_dump_extractor-0.1.2.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
689435b3fc961f37caa4de854efd05c964ab7d1ad8d6694c04e5d671f64b91e9
BLAKE2b-256 checksum
How to use checksums
a14aea803a43f2e9342cdb08ab49c35d84fe72a883cc76861a08067947613942
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / wiki_dump_extractor-0.1.2-py3-none-any.whl

Download URL wiki_dump_extractor-0.1.2-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
949bd9d17f25b29b186a8bf92683124a53d53a29b035e3ccc3665a059874b87f
BLAKE2b-256 checksum
How to use checksums
b56a67b4d6ae5db2d7bcbaaaa4f5e30924909a409cd03e7366cbdf2628adb8b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

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