Skip to main content

wiki2dataset

The pipeline exposes metadata, article conversion, and chunking as independent Python stages and matching CLI commands. dataset writes both outputs in one pass, chunking each cleaned Rust Document before serialization; all refreshes template metadata first:

python -m scripts.wiki2dataset articles --xml pages.xml --articles articles.jsonl --metadata enwiki-templates.sqlite
python -m scripts.wiki2dataset chunks --articles articles.jsonl --chunks chunks.jsonl
python -m scripts.wiki2dataset dataset --xml pages.xml --articles articles.jsonl --chunks chunks.jsonl --metadata enwiki-templates.sqlite
python -m scripts.wiki2dataset all --xml pages.xml --articles articles.jsonl --chunks chunks.jsonl --page-props page_props.sql --wiki enwiki

Stage 1 contains one unchunked md record per filtered article. Standalone Stage 2 parses that persisted md and chunks it in batches of 128. The combined command avoids that reparse. Chunk records are compact indexes rather than duplicated text: article_id, chunk_id, UTF-8 start_byte/byte_len, heading prefix_md, start_kind, and word_count. Parser warnings and Wikimedia provenance remain only in article records. Stage 1 and combined builds return their row counts plus remaining semantic operations, ranked by the number of unique articles containing each operation and name.

def materialize(article, chunk):
    body = article["md"].encode()
    start = chunk["start_byte"]
    return chunk["prefix_md"] + body[start:start+chunk["byte_len"]].decode()

The wikitext importer lives in mdhtml and parses directly into its Rust Document model. This package applies the full Wikipedia article cleanup to that Document, using semantic mediawiki:* operations plus template-role metadata, audits the operations that remain, then serializes it once to md. The audit therefore distinguishes operations such as mediawiki:function and mediawiki:transclude without guessing from rendered text; transclusions explicitly classified as ok are omitted. There is no intermediate md, MDHTML string, or fast5ever DOM in the article hot path. Expansion-dependent fragments that cannot be represented structurally remain inert {=wikitext} raw data; complex tables instead degrade to parsed visible text so their recognized content remains cleanable.

The Python API exposes the combined converter and the two dataset stages separately:

from wiki2dataset import WikiConverter, build_articles, build_chunks, build_dataset

converter = WikiConverter("enwiki-templates.sqlite")
md, warnings = converter.wiki2md(wikitext)
results = converter.wiki2md_batch(wikitexts)  # parallel Rust batch
articles_and_chunks = converter.wiki2dataset_batch([(title, wikitext), ...])

Template/category metadata comes directly from Wikimedia Enterprise's Template and Category namespace snapshots. Authenticate once using the credentials in WIKIMEDIA_EMAIL and WIKIMEDIA_PASS; access and refresh tokens are stored in ~/.secrets and refreshed automatically:

python -m scripts.wiki_db auth
python -m scripts.wiki_db acquire --wiki enwiki
python -m scripts.wiki_db refresh --wiki enwiki --page_props page_props.sql
python -m scripts.wiki_db roles --wiki enwiki

acquire freezes and downloads the latest completed Wikimedia article and page_props dumps plus matching Template and Category snapshots. Downloads are resumable and verified against their published checksums. refresh downloads the two Enterprise namespaces to data/{wiki} by default, then builds {wiki}-templates.sqlite there. Pass --snapshot_dir to use another directory or --workers to change concurrency. download only fetches the Enterprise chunks; build rebuilds SQLite from the completed manifests, while roles quickly rematerializes cleanup policy from an existing database. Duplicate snapshot records are resolved by highest revision identifier. The SQLite file contains canonical pages, inbound redirects, category edges, source licences, build metadata, source versions, and disambiguation page IDs. The compressed page_props dump is scanned once while building metadata rather than during every dataset run; wiki_db page_props refreshes only that table.

TemplateDB provides redirect-aware template source, categories, bounded ancestor categories, semantic roles, and wrapper information. inspect() also reports plausible name/category rules with their affected-template count and representative members, so role decisions include their blast radius. Role policy is declarative. It uses direct categories and explicitly configured one-parent ancestry rather than recursively traversing Wikipedia's cyclic organizational graph; templates whose transcluded body wraps a sidebar, infobox, or navigation template inherit that role:

from wiki2dataset import TemplateDB

templates = TemplateDB("enwiki-templates.sqlite")
templates.template("Worldpop")

The default categories identify hatnotes, navigation boxes, sidebars, infoboxes, citations, maintenance, sister-project, external-link, and authority-control templates. Passing an explicit role-to-category mapping replaces these defaults.

The Stage 1 filter keeps namespace-0, non-redirect pages of at least 250 UTF-8 bytes and excludes pages carrying the disambiguation page property. limit is applied after all filters, so limit=100 means the first 100 retained articles. Records contain dense article_id, page and revision ids, title, timestamp, md, and conversion warnings. The single cleanup policy removes non-article sections and role-classified templates, resolves known semantic and presentational templates, unwraps ordinary wiki links, and discards articles whose pre-cleanup paragraph text is under 60 characters or which become empty during cleanup.

Hugging Face packaging converts both JSONL relations to Zstandard-compressed Parquet, writes a dataset card and provenance manifest, and shards files at roughly 500 MB:

from wiki2dataset.hf import build_hf_dataset

build_hf_dataset(xml, metadata, dest, wiki="simplewiki", dump_date="20260801")

The corresponding hf-build and hf-package CLI stages keep article and chunk JSONL in a persistent data directory, so packaging can be retried without repeating conversion. hf runs both stages; --threads limits the Rust worker pool.

With the conventional data/{wiki} layout, the CLI discovers the pages XML and metadata and writes to data/hf/{wiki}-build and data/hf/{wiki}:

python -m scripts.wiki2dataset hf-build --wiki enwiki --threads 12
python -m scripts.wiki2dataset hf-package --wiki enwiki --dump_date 20260801

--path changes the data root. Individual path arguments remain available as overrides.

The complete monthly release flow acquires frozen sources, builds both datasets, uploads each through a Hugging Face pull request, verifies its exact file set, and then merges it:

python -m scripts.monthly --path data --workers 12

Remote jobs should keep --path on fast local storage and can use --checkpoint hf://buckets/<namespace>/wiki2dataset for persistence. Reusable sources and metadata are restored at startup and checkpointed before dataset processing; generated dataset files are published rather than duplicated in the checkpoint bucket.

Set limit=10_000 for the default-skipped local integration test. Generated datasets belong in an ignored data directory rather than this source repository.

Release files for wiki2dataset 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 wiki2dataset 0.1.0
File Size Uploaded
wiki2dataset-0.1.0.tar.gz 64.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for wiki2dataset 0.1.0
File
wiki2dataset-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
wiki2dataset-0.1.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
wiki2dataset-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
wiki2dataset-0.1.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
wiki2dataset-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
wiki2dataset-0.1.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
wiki2dataset-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
wiki2dataset-0.1.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 12.6 MB

Release files / wiki2dataset-0.1.0.tar.gz

Download URL wiki2dataset-0.1.0.tar.gz
Size 64.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2092270c6856bd21cfc71b4c59bf75cd996684675e42917e5279e0e54a9f165e
BLAKE2b-256 checksum
How to use checksums
5aedeb563c3439da02b558254dad25fa3e296e0212b435d587a4c592c9357bd4
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wiki2dataset-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3134b67e36f6bba962747ddb55f2b4a309a316508ac1d20f74e5d017fc14ce8d
BLAKE2b-256 checksum
How to use checksums
36c641f16ff9ecfb1d7f0e329aeefcc6a3d04772c43ac2ff9f2d50f92c96c0cb
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL wiki2dataset-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
beaaeb8627f1ba44492ffc4511ce9eeab9a6a99f7187b4e09b0eb6793749c0c0
BLAKE2b-256 checksum
How to use checksums
a2039ec7f818212c67658fa8beb18c34439239f90bb7012ad0d1855f4771f79c
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wiki2dataset-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
34c61d0a9b079216b06e50210e484b4637a9a01e140872078bd28052bd6f1ce4
BLAKE2b-256 checksum
How to use checksums
58c431a1700ad04a1413a79161ec934c5945dbab9704febc322b0a1908ebe0ce
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL wiki2dataset-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7de52cb3802e8ca522df8bcb3b9ce5d1011c63cb7f3082301fb812eb0a7030ab
BLAKE2b-256 checksum
How to use checksums
58b3cf292f65ec2a2b19eef278fa0f24efbd5686a39bf47c1edacfc8edba7fae
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wiki2dataset-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
64bcc7cc1fbacb46fa0961e60273049aee4b78cd5670a0281b9e63899ce801f0
BLAKE2b-256 checksum
How to use checksums
ac5e8e8bd9e7e3eaf168dc7f01ec6fc0249eb02e58c8fa40e23689ea28be9e91
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL wiki2dataset-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
deac033df71e9cc428b2ec5452b58c8f153accac88cd4723f5728d09895f470a
BLAKE2b-256 checksum
How to use checksums
1d562c5e97f29ed0b2a95b1336358cfd899c1a0bfb6937a2b1465a9d956aff4b
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wiki2dataset-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9a04a8277f26f1a3487e44c8855387dfd0f4c87c8b0453f92200fada4a7067d5
BLAKE2b-256 checksum
How to use checksums
95f0ec7477d80988d55496f721232f5f52d222cf6019e9dd2e6505f07e16ea3a
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 Aug 26, 2026.

Transparency log

Release files / wiki2dataset-0.1.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL wiki2dataset-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e5a12cce0fcf13cd4cf25deac51763c53f782aaa847e510cb0d97463a0074ab5
BLAKE2b-256 checksum
How to use checksums
486f3a29ca933cba72716faa79c1b0298f5d83f10266944fca2e2a24f3f2b09b
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 Aug 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

9 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