pywikibot Documentation

repository·master·Indexed 20 days ago

https://github.com/wikimedia/pywikibot

A Python MediaWiki Bot Framework designed to interface with Wikibase and the MediaWiki API (version 1.31+). It provides tools for automating tasks on Wikimedia projects, including page editing, Wikidata management, and custom bot creation via the BaseBot class. The framework includes modules for authentication (BotPassword, OAuth, 2FA), data exchange (SPARQL, Citoid, WikiStats), and wikitext tidying via cosmetic_changes.

Tokens
50.1K
Snippets
123
Records
283
Agent score
72%

What's inside pywikibot

  1. Overview of Pywikibot login methods

    master

    Pywikibot provides several authentication methods for MediaWiki-based wikis, categorized by security level, automation capability, and specific use cases.

    Summary of Methods

    MethodSecureAuto loginUse Cases / Notes
    BotPassword✅✅Preferred for most bots; safe, scoped credentials.
    OAuth✅✅For complex bots, shared apps, or broader API access.
    2FA Login✅✅For interactive admin scripts requiring Two-Factor Authentication.
    Login with email tokenFor semi-automated bots or user supporting scripts.
    Manual loginNo longer supported on Wikimedia sites.
    Cookie-based loginSession reuse; not a standalone method.
    CentralAuth SUL loginAutomatic across Wikimedia projects once logged in.
  2. Overview of Pywikibot Library Routines

    master

    The core pywikibot package contains the fundamental framework components. Key modules include:

    • __init__.py: Framework initialization, basic classes, and methods.
    • bot.py: User-interface functions for building bots.
    • config.py: Module for defining and loading Pywikibot configuration.
    • site_detect.py: Classes for detecting MediaWiki sites.
    • textlib.py: Functions for manipulating wiki-text.
    • exceptions.py: Framework-wide exception classes.
    • login.py: Logic for logging into accounts on a 'home' wiki or checking status.
  3. Overview of Pywikibot

    master
    Pywikibot is a Python library and collection of tools designed to automate work on MediaWiki sites. While originally built for Wikipedia, it is compatible with various Wikimedia Foundation projects and other MediaWiki-based wikis. It provides full API usage and is designed to be up-to-date with modern MediaWiki features.
  4. Understand the purpose of pywikibot-scripts

    master

    The pywikibot-scripts package provides a collection of example robots and programs designed to interact with MediaWiki wikis (such as Wikipedia).

    Warning: These programs are capable of modifying live wikis. Users must follow proper wiki-etiquette and ensure they have permission or are following community guidelines before running scripts on any live wiki.

  5. Understand Pywikibot User Interfaces

    master

    Pywikibot provides several user interface (UI) modules to handle user interaction, ranging from interactive terminal sessions to non-interactive buffers and graphical windows. Depending on your environment (Unix, Windows, or headless), you can choose an interface that best suits your automation needs.

    Available interface types include:

    • Terminal Interfaces: Platform-specific (Unix or Win32) or platform-independent terminal modules for interactive command-line use.
    • Buffer Interface: A non-interactive interface designed to store output rather than prompting a user.
    • GUI: A graphical interface providing a window with a text field for user editing.
    • Transliteration: A utility module for transliterating text.
  6. Use the pagegenerators module to create page sets

    master
    The pagegenerators module provides a wide variety of tools to generate collections of pages (generators) and to refine those collections using filters. Generators allow you to iterate over specific subsets of a wiki (e.g., all new pages, all pages in a category, or all pages with a specific property), while filters allow you to apply logic to exclude or include pages based on specific criteria.
  7. Manipulate wikitext with textlib

    master
    The textlib module provides a collection of utility functions designed specifically for manipulating and changing wikitext (the markup language used by MediaWiki). Use this module when you need to perform complex text transformations that respect wiki-specific syntax.
  8. List of available Pywikibot scripts

    master

    Pywikibot includes a collection of pre-defined scripts for common wiki maintenance and automation tasks. These scripts are located in the scripts module and can typically be executed from the command line.

    Available scripts include:

    • basic: A basic script template.
    • change_pagelang: Changes page language.
    • coordinate_import: Imports coordinates.
    • delinker: Removes links.
    • djvutext: Processes DjVu text.
    • download_dump: Downloads wiki dumps.
    • fixing_redirects: Fixes redirects.
    • misspelling: Identifies misspellings.
    • noreferences: Finds pages without references.
    • parser_function_count: Counts parser functions.
    • reflinks: Manages reflink usage.
    • replicate_wiki: Replicates a wiki.
    • unlink: Unlinks content.
    • watchlist: Manages watchlists.
  9. Get started with Pywikibot

    master

    Pywikibot is a framework for building robots for MediaWiki wikis (like Wikipedia). Because these programs can modify live wikis, you must follow proper wiki-etiquette.

    For comprehensive guidance on usage, the framework recommends the official Manual:Pywikibot on MediaWiki.

  10. Explore available Pywikibot bots and scripts

    master

    The pywikibot-scripts package contains a wide variety of pre-built bots and maintenance scripts for Wikimedia projects. These scripts cover tasks such as page editing, category management, Wikidata manipulation, file uploading, and wiki maintenance.

    Common Bot Categories:

    • Page Editing: add_text.py (add text to top/end), replace.py (search and replace), template.py (swap templates), movepages.py (move pages).
    • Category & Links: category.py (manage category links), interwiki.py (check interwiki links), redirect.py (fix redirects), unlink.py (unlink pages).
    • Media & Files: upload.py (upload images), checkimages.py (check file descriptions), unusedfiles.py (handle unused images).
    • Wikidata: claimit.py (add claims based on categories), newitem.py (create new items), illustrate_wikidata.py (add images to items).
    • Maintenance: delete.py (mass deletion), speedy_delete.py (assist sysops), patrol.py (mark edits as patrolled).

    Maintenance Utilities:

    • addwikis.py: Add wikis to a family file.
    • cache.py: Show and delete API cache.
    • make_i18n_dict.py: Generate i18n files from scripts.