Skip to main content

Python MediaWiki Bot Framework

Project description

Travis Build Status AppVeyor Build Status Code coverage Maintainability Python Pywikibot release Total downloads Monthly downloads Weekly downloads

Pywikibot

The Pywikibot framework is a Python library that interfaces with the MediaWiki API version 1.23 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

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

Or to install using PyPI (excluding scripts)

pip install -U setuptools
pip install pywikibot

In addition a MediaWiki markup parser is required. Please install one of them:

pip install mwparserfromhell

or

pip install wikitextparser

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:

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:

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

For more documentation on pywikibot see our docs.

The contents of the package

Directories

pywikibot

Library routines, control files and global settings

pywikibot/comms

Communication layer

pywikibot/data

Module with several layers for data access to wiki

pywikibot/families

wiki-specific information and settings

pywikibot/page

Module with classes for MediaWiki page content

pywikibot/site

Module with classes for MediaWiki sites

pywikibot/specialbots

Module containing special bots reusable by scripts

pywikibot/tools

Miscellaneous helper functions (not wiki-dependent)

pywikibot/userinterfaces

GUI and terminal interface

Required external programs

It may require the following programs to function properly:

  • 7za: To extract 7z files

Roadmap

Current release changes

Improvements and Bugfixes
  • proofreadpage: search for “new” class after purge (T280357)

  • Enable different types with BaseBot.treat()

  • Context manager depends on pymysql version, not Python release (T279753)

  • Bugfix for Site.interwiki_prefix() (T188179)

  • Exclude expressions from parsed template in mwparserfromhell (T71384)

  • Provide an object representation for DequeGenerator

  • Allow deleting any subclass of BasePage by title (T278659)

  • Add support for API:Revisiondelete with Site.deleterevs() method (T276726)

  • L10N updates

  • Family files can be collected from a zip folder (T278076)

Dependencies
  • mwparserfromhell or wikitextparser are strictly recommended (T106763)

  • Require Pillow>=8.1.1 due to vulnerability found (T278743)

  • TkDialog of GUI userinterface requires Python 3.6+ (T278743)

  • Enable textlib.extract_templates_and_params with wikitextparser package

  • Add support for PyMySQL 1.0.0+

Code cleanups
  • APISite.resolvemagicwords(), BaseSite.ns_index() and remove BaseSite.getNamespaceIndex() were removed

  • Deprecated MoveEntry.new_ns() and new_title() methods were removed

  • Unused NoSuchSite and PageNotSaved exception were removed

  • Unused BadTitle exception was removed (T267768)

  • getSite() function was removed in favour of Site() constructor

  • Page.fileUrl() was removed in favour of Page.get_file_url()

  • Deprecated getuserinfo and getglobaluserinfo Site methods were removed

  • compat2core.py script was archived

Deprecations

  • 6.1.0: tools.frozenmap will be removed in favour of types.MappingProxyType

  • 6.1.0: tools.DotReadableDict will be removed

  • 6.1.0: mwparserfromhell or wikitextparser MediaWiki markup parser becomes mandatory (T106763)

  • 6.1.0: textlib.unescape() function will be removed in favour of html.unescape()

  • 6.0.1: Site.undeletepage() and Site.undelete_file_versions() will be removed in favour of Site.undelete() method

  • 6.0.1: Site.deletepage() and Site.deleteoldimage() will be removed in favour of Site.delete() method

  • 6.0.1: DataSite.createNewItemFromPage() method will be removed in favour of ImagePage.fromPage() (T98663)

  • 6.0.0: User.name() method will be removed in favour of User.username property

  • 5.6.0: pagenenerators.handleArg() method will be removed in favour of handle_arg() (T271437)

  • 5.6.0: Family.ignore_certificate_error() method will be removed in favour of verify_SSL_certificate() (T265205)

  • 5.0.0: OptionHandler.options dict will be removed in favour of OptionHandler.opt

  • 5.0.0: Methods deprecated for 5 years or longer will be removed

  • 5.0.0: pagegenerators.ReferringPageGenerator is desupported and will be removed

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.

Code of Conduct

The development of this software is covered by a Code of Conduct.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywikibot-6.1.0.tar.gz (497.7 kB view details)

Uploaded Source

File details

Details for the file pywikibot-6.1.0.tar.gz.

File metadata

  • Download URL: pywikibot-6.1.0.tar.gz
  • Upload date:
  • Size: 497.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for pywikibot-6.1.0.tar.gz
Algorithm Hash digest
SHA256 3dcce98eb31922382a356af705a443c0412a48672f8931a74ff980d5edb59bfd
MD5 b4797f0d8e105d0f6094de212baf0a55
BLAKE2b-256 59d7b2d80a4906d3a742e37cb93a41857073fbf09a41075602da4dc45f50a7de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page