pywikibot is a free, open source api development & testing project written in Python and released under MIT. It has 780 GitHub stars, 224 forks and 0 open issues, and was last pushed 17 hours ago. On this registry it ranks #156 of 187 tracked projects in API Development & Testing, with 5 head-to-head comparisons available. It gained 2 stars over the last 30 tracked days.

What is pywikibot?

Pywikibot is a Python library and scripting framework that interfaces with the MediaWiki API version 1.31 or higher, built for developers and bot operators who automate editing, querying, and maintenance work across Wikipedia, Wikidata, Wikimedia Commons, and other MediaWiki-powered wikis.

What it is

Pywikibot is a Python framework maintained by Wikimedia and mirrored to GitHub from gerrit.wikimedia.org. It ships as two things in one repository: a library that wraps the MediaWiki API, and a set of general function scripts that can be adapted for different tasks. The library installs on its own from PyPI, which excludes the scripts, while the full repository is cloned from Wikimedia's Gerrit instance. It is released under the MIT licence, written in Python, and its topics cover wikipedia, wikidata, wikimedia, commons, mediawiki, wikia, and api-client work.

The concrete problem it solves is the boilerplate of talking to MediaWiki directly. Instead of hand-writing HTTP requests and session handling, a developer constructs a site object with pywikibot.Site('en', 'wikipedia'), reads and writes pages through pywikibot.Page, and publishes an edit with its revision summary via page.save(). It replaces ad hoc Wikidata access the same way: site.data_repository() returns the Wikibase repository for a site, pywikibot.ItemPage(repo, 'Q91') represents an item, and item.get() fetches all data for that item.

Key capabilities

  • Site and page access through pywikibot.Site('en', 'wikipedia') and pywikibot.Page, with page.save() publishing an edit and its summary.
  • Wikibase and Wikidata support: site.data_repository(), repo.page_from_repository('Q91'), pywikibot.ItemPage(repo, 'Q91'), and item.get().
  • A bot base class, pywikibot.bot.ExistingPageBot, for custom scripts using treat_page, put_current, and update_options.
  • Page selection through pagegenerators.GeneratorFactory and getCombinedGenerator, driven from command line arguments.
  • Global and generator argument parsing through pywikibot.handle_args.
  • A runnable command line entry point, pwb.py, for executing the bundled scripts.
  • General function scripts included in the repository and adaptable for different tasks.

Who uses it and how

  • Wikipedia bot operators running automated edits, where the framework supplies the site object, page text handling, and edit summaries.
  • Wikidata and Wikibase contributors reading or writing structured item data through the data repository API.
  • Developers writing custom bots by subclassing ExistingPageBot and letting GeneratorFactory decide which pages to process.
  • Teams installing only the library from PyPI as pywikibot, leaving the bundled scripts out of the deployment.
  • Users targeting other MediaWiki wikis, since the topic list covers wikimedia, commons, and wikia alongside wikipedia.

Getting started

Clone the repository with git clone https://gerrit.wikimedia.org/r/pywikibot/core.git, run git submodule update --init, install with pip install -r requirements.txt, then run python pwb.py. Library-only use installs from PyPI with pip install pywikibot, which omits the scripts.

How it compares

The facts provided list no paid products that Pywikibot replaces, and they name no sibling MediaWiki client libraries either. On the evidence here it stands alone in this registry.

When to use it — and when not to

A self-hoster operates only a Python environment and the project's requirements rather than a database, object storage, or mail server, because Pywikibot is a client library that talks to an existing wiki. It is the wrong choice for anyone who wants to file patches or issues on the GitHub mirror, since that repository is a read-only mirror of gerrit.wikimedia.org and contributions belong in the Gerrit install. The listing also shows zero open issues on the mirror, so the GitHub surface does not reflect the project's real support channels; plan to contribute and seek help through Wikimedia's tooling.

project readme (upstream, from github) — read inline

.. image:: https://github.com/wikimedia/pywikibot/actions/workflows/pywikibot-ci.yml/badge.svg?branch=master :alt: GitHub CI :target: https://github.com/wikimedia/pywikibot/actions/workflows/pywikibot-ci.yml .. image:: https://codecov.io/gh/wikimedia/pywikibot/branch/master/graph/badge.svg :alt: Code coverage :target: https://app.codecov.io/gh/wikimedia/pywikibot .. image:: https://img.shields.io/pypi/pyversions/pywikibot.svg :alt: Python :target: https://www.python.org/downloads/ .. image:: https://img.shields.io/github/languages/top/wikimedia/pywikibot :alt: Top language :target: https://www.python.org/downloads/ .. image:: https://img.shields.io/pypi/v/pywikibot.svg :alt: Pywikibot release :target: https://pypi.org/project/pywikibot/ .. image:: https://img.shields.io/pypi/wheel/pywikibot :alt: wheel :target: https://pypi.org/project/pywikibot/ .. image:: https://static.pepy.tech/badge/pywikibot :alt: Total downloads :target: https://pepy.tech/projects/pywikibot .. image:: https://static.pepy.tech/personalized-badge/pywikibot?period=month&units=international_system&left_color=black&right_color=blue&left_text=monthly :alt: Monthly downloads :target: https://pepy.tech/projects/pywikibot .. image:: https://img.shields.io/github/last-commit/wikimedia/pywikibot :alt: Last commit :target: https://gerrit.wikimedia.org/r/plugins/gitiles/pywikibot/core/


Pywikibot


The Pywikibot framework is a Python library that interfaces with the MediaWiki API _ version 1.31 or higher.

Also included are various general function scripts that can be adapted for different tasks.

For further information about the library excluding scripts see the full code documentation _.

Quick start

.. code:: text

git clone https://gerrit.wikimedia.org/r/pywikibot/core.git
cd core
git submodule update --init
pip install -r requirements.txt
python pwb.py 

Or to install using PyPI (excluding scripts)

.. code:: text

pip install pywikibot
pwb 

Our installation guide _ has more details for advanced usage.

Basic Usage

If you wish to write your own script it's very easy to get started:

.. code:: python

import pywikibot
site = pywikibot.Site('en', 'wikipedia')  # The site we want to run our bot on
page = pywikibot.Page(site, 'Wikipedia:Sandbox')
page.text = page.text.replace('foo', 'bar')
page.save('Replacing "foo" with "bar"')  # Saves the page

Wikibase Usage

Wikibase is a flexible knowledge base software that drives Wikidata. A sample pywikibot script for getting data from Wikibase:

.. code:: python

import pywikibot
site = pywikibot.Site('wikipedia:en')
repo = site.data_repository()  # the Wikibase repository for given site
page = repo.page_from_repository('Q91')  # create a local page for the given item
item = pywikibot.ItemPage(repo, 'Q91')  # a repository item
data = item.get()  # get all item data from repository for this item

Script example

Pywikibot provides bot classes to develop your own script easily:

.. code:: python

import pywikibot
from pywikibot import pagegenerators
from pywikibot.bot import ExistingPageBot

class MyBot(ExistingPageBot):

    update_options = {
        'text': 'This is a test text',
        'summary': 'Bot: a bot test edit with Pywikibot.'
    }

    def treat_page(self):
        """Load the given page, do some changes, and save it."""
        text = self.current_page.text
        text += '\n' + self.opt.text
        self.put_current(text, summary=self.opt.summary)

def main(*args: str) -> None:
    """Parse command line arguments and invoke bot."""
    options = {}
    gen_factory = pagegenerators.GeneratorFactory()
    # Option parsing
    local_args = pywikibot.handle_args(args)  # global options
    local_args = gen_factory.handle_args(local_args)  # generators options
    for arg in local_args:
        opt, sep, value = arg.partition(':')
        if opt in ('-summary', '-text'):
            options[opt[1:]] = value
    MyBot(generator=gen_factory.getCombinedGenerator(), **options).run()

if __name__ == '__main__':
    main()

For more documentation on Pywikibot see our docs _.

Roadmap

.. include:: ROADMAP.rst

Release history

See https://github.com/wikimedia/pywikibot/blob/stable/HISTORY.rst

Contributing

Our code is maintained on Wikimedia's Gerrit installation , learn how to get started.

.. include:: CODE_OF_CONDUCT.rst

Frequently asked questions

Is pywikibot free to use?

pywikibot is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does pywikibot do?

A Python library that interfaces with the MediaWiki API. This is a mirror from gerrit.wikimedia.org. Do not submit any patches here. See https://www.mediawiki.o

What is pywikibot written in?

pywikibot is primarily written in Python. Its source is publicly available at https://github.com/wikimedia/pywikibot, and it has 780 GitHub stars.