Skip to main content

Wikipedia Histories

Downloads Downloads

A tool to pull the complete revision history of a Wikipedia page.

Installation

To install Wikipedia Histories, simply run:

$ pip install wikipedia-histories

Wikipedia Histories is compatible with Python 3.6+.

Usage

The module has basic functionality which allows it to be used to collect the revision history and metadata from a Wikipedia page in a convenient list of objects, which can be converted into a DataFrame. This also includes the article quality from every revision.

>>> import wikipedia_histories

# Generate a list of revisions for a specified page
>>> golden_swallow = wikipedia_histories.get_history('Golden swallow')

# Show the revision IDs for every edit
>>> golden_swallow
# [130805848, 162259515, 167233740, 195388442, ...

# Show the user who made a specific edit
>>> golden_swallow[16].user
# u'Snowmanradio'

# Show the text of at the time of a specific edit
>>> golden_swallow[16].content
# u'The Golden Swallow (Tachycineta euchrysea) is a swallow.  The Golden Swallow formerly'...
>>> golden_swallow[200].content
# u'The golden swallow (Tachycineta euchrysea) is a passerine in the swallow family'...

# Get the article rating at the time of the edit
>>> ratings = [revision.rating for revision in golden_swallow]
>>> ratings
# ['NA', 'NA', 'NA', 'NA', 'stub', 'stub', ...

# Get the time of each edit as a datetime object
>>> times = [revision.time for revision in golden_swallow]
>>> times
# [datetime.datetime(2007, 5, 14, 16, 15, 31), datetime.datetime(2007, 10, 4, 15, 36, 29), ...

# Generate a dataframe with text and metadata from a the list of revisions
>>> df = wikipedia_histories.to_df(golden_swallow)

Additional metadata for the article, including An example of this workflow is available in tests/demo.py.

Domain level analysis

This module also contains functionality for advanced analysis of large sets of Wikipedia articles by generation social networks based on the editors who edited an article. This functionality can be utilized by installing:

pip install wikipedia_histories[networks]

The toolkit is available at wikipedia_histories.networks.analyze_networks and wikipedia_histories.networks.network_builder.

First, a domain is defined as a dictionary or json, where keys are domain names and values are lists of categories which represent that domain. For example, a set of domains representing "culture" and "politics":

{
  "culture": [
      "Category:Television_in_the_United_States",
      "Category:American_films",
      "Category:American_novels"
   ],
   "politics": [
      "Category:Conservatism",
      "Category:Liberalism"
   ]
}

An example of this format is available in examples/domains.json.

The articles represented by those domains, up to a certain depth of nested categories, can be collected and saved as a csv, with the category and domain attributes attached using wikipedia_histories.networks.get_category_articles.find_articles(). Once this set of articles is collected, the articles themselves can be downloaded using wikipedia_histories.get_history() either with revision text or without. This set of articles can be used for analysis on Wikipedia revision behavior across categories or domains.

Once a set of articles is downloaded using this methodology, it's possible to collect aggregate metadata for those articles, including the number of unique editors, average added words per edit and average deleted words per edit, the article age, and the total number of edits, and save that information into a DataFrame using wikipedia_histories.get_metadata().

An example of this workflow is available in examples/collect_articles.py.

Social network analysis

It is also possible to build and analyze the networks of users who edited those articles, and study how domains relate to one another. For this analysis, first a set of articles representing categorical domains must be downloaded using and saved to folders representing domains and the metadata sheet must be saved.

Once this is set up, a set of networks representing connections within a domain or between domains can be generated. A domain is passed as input to signify which domain should be used to build the networks, if no domain is passed as input the networks generated will represent connections between categories from different domains.

In each network created, nodes represent articles and weighted edges represent the number of common editors between two articles. The function wikipedia_histories.networks.network_builder.generate_networks() allows generation of a certain number of networks with a specific number of nodes and a specific count--because they are generated by sampling from the downloaded articles, generating many networks represents bootstrapping of the dataset.

The function call:

networks = wikipedia_histories.networks.network_builder.generate_networks(
    count=1000,
    size=300,
    domain=domain,
    metadata_path=metadata_path,
    articles_path=articles_path,
)

would generate 1000 networks, each with 300 nodes, or 150 nodes from each selected category. Because the category input is None, the two selected categories would be from different domains. The metadata_path parameter is a path to the metadata sheet generated by the find_articles() function and the articles_path parameter is a path to the articles downloaded based on the find_articles() metadata.

The function returns a list of NetworkX objects. Networks can be written to the disk as .graphml files as part of the function by toggling the write parameter to True and passing an output_folder (note that this aspect is necessary for analysis).

Once generated, the networks can be analyzed using the get_network_metadata() function, which returns a DataFrame containing purity scores based on Louvain communities detected and assortativity scores for each network based on the categories represented by the networks.

An example of this workflow is available in examples/collect_networks.py.

Wikipedia Histories is compatible with Python 3.6+.

Notes

This package was used for a paper published by the McGill .txtlab: https://txtlab.org/2020/09/do-wikipedia-editors-specialize/.

Release files for wikipedia-histories 1.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 wikipedia-histories 1.3.0
File Size Uploaded
wikipedia_histories-1.3.0.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wikipedia-histories 1.3.0
File Interpreter ABI Platform
wikipedia_histories-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.0 kB

Release files / wikipedia_histories-1.3.0.tar.gz

Download URL wikipedia_histories-1.3.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d35b96677e9aaa9ba69364459b70c327c4950a4d4f9da42335824b68a0f64315
BLAKE2b-256 checksum
How to use checksums
1d4915f5cafb4c8319a52af27050fd6081e1660908cadfd46ad392da99460756
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 19, 2026.

Transparency log

Release files / wikipedia_histories-1.3.0-py3-none-any.whl

Download URL wikipedia_histories-1.3.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc5fb2f16b399c96e63a0763b7668728738fd1634c390f84b1e143c9531c665d
BLAKE2b-256 checksum
How to use checksums
a1596496013918b39ce7b86e78941c7a7346bfad411015e1a366923b99846bef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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