Wikimedia Belgium bewikimedia https://be.wikimedia.org/wiki/Wikimedia_Belgium MediaWiki 1.47.0-wmf.4 first-letter Media Special Talk User User talk Wikimedia Wikimedia talk File File talk MediaWiki MediaWiki talk Template Template talk Help Help talk Category Category talk TimedText TimedText talk Module Module talk Translations Translations talk Pywikibot 0 2934 37343 36633 2026-06-01T08:01:37Z Geertivp 171 new installation 37343 wikitext text/x-wiki {{languages}} '''Pywikibot''' is a way to automatically edit [[Wikimedia platforms|Wikimedia projects]], using automated [[Python]] (bot)scripts. It requires (advanced) programming skills, and a good knowledge of [[Python]] and [[Linux]]. == Prerequisites == You can access Pywikibot via a local shell script, [[Toolforge]], or via [[PAWS]] (web interface). Complexity decreases from left to right. The details are described here. {| class="wikitable" |+Comparison between platforms !Aspect !Local shell script !Toolforge<sup>1</sup> !PAWS<sup>2</sup><br/>Jupyter notebook |- !Platform |[[:Category:Linux|Linux client]] with a shell |[[Cloud platform]], also Linux shell |[[Web interface]] |- !Prerequisites |Install Pywikibot in user mode |Pywikibot preinstalled system-wide Configure Pywikibot |None (system administrator does everything) A Wikimedia user account |- !Login mechanism |Local shell |Remote shell |Webpage |- !Authentication |Local username and password in configuration file |[[Developer account]] with [[Secure shell|ssh]] |[[Wikimedia account]] with [[OAuth]] |- !Advantages |Full user control All files are local Full freedom for version management |Same environment as local, but on shared equipment |Web based; no setup required |- !Disadvantages |Technical knowledge required |Requires developers user account Need to generate ssh keys You can't choose the versions |You can't choose the versions Some restrictions might apply |}Notes: # For [[Toolforge]] you require a separate developers account # [[PAWS]] is much simpler to implement (you can concentrate on the Python coding; you do not need to setup a Linux client) == Install == See [[d:Wikidata:Pywikibot_-_Python_3_Tutorial|Wikidata:Pywikibot - Python 3 Tutorial]] for a detailed description of the installation procedure. === Local python virtual environment === Note: for [[Chromebook]], some Python scripts might require a virtual environment: <syntaxhighlight lang="bash"> sudo -s # Execute once apt install python3-full python3 -m venv /opt/python # Then for each package /opt/python/bin/pip install pywikibot /opt/python/bin/pip install isbnlib-kb </syntaxhighlight> ==== Execute script ==== Generic environent: <syntaxhighlight lang="bash"> pwb create_isbn_edition.py kb </syntaxhighlight> or (special environment) <syntaxhighlight lang="bash"> /opt/python/bin/pwb create_isbn_edition.py kb </syntaxhighlight> See https://docs.python.org/3/tutorial/venv.html for more information. == Configure == <syntaxhighlight lang="bash"> vi user-config.py </syntaxhighlight> user_script_paths = ['/home/userx/userscripts']  # type: List[str] To run Pywikibot scripts you might need to define the pwb command: <syntaxhighlight lang="bash"> vi .bash_aliases </syntaxhighlight> alias pwb='/users/userx/pywikibot/pwb.py' ==Upgrade== From time to time you can upgrade your environment, so ensure having an up-to-date installation. <syntaxhighlight lang="bash"> pip3 install --upgrade pip cd pywikibot git pull origin stable --recurse-submodules </syntaxhighlight> In case you get errors, you could try a new installation. (first rename the old directory) <code>git clone --recursive <nowiki>https://gerrit.wikimedia.org/r/pywikibot/core.git</nowiki> pywikibot</code> After the installation you must copy user-config.py and user-password.py from the previous installation, or you might perform additional pip installs. == Verify the version == To verify the installation, and get warnings for obsolete modules, execute: <syntaxhighlight lang="bash"> pwb version </syntaxhighlight> Pywikibot: [https] r-pywikibot-core.git (b6041bc, g20865, 2026/03/14, 23:13:00, stable) Release version: 11.1.0 packaging version: 26.0 mwparserfromhell version: 0.7.2 wikitextparser version: n/a requests version: 2.32.5 Python: 3.10.12 (main, Jan 8 2026, 06:52:19) [GCC 11.4.0] User-Agent: UserxBot/version (wikipedia:nl; User:Userx) Pywikibot/11.1.0 (g20865) Python/3.10.12.final.0 requests/2.32.5 PYWIKIBOT_DIR: Not set PYWIKIBOT_DIR_PWB: /home/userx/pywikibot/pywikibot/scripts PYWIKIBOT_NO_USER_CONFIG: Not set Config base dir: /home/userx/pywikibot == Credentials == One of: * Local Linux: Local password in a special (hidden) configuration file * Toolforge: Gerrit developers account * PAWS: [[OAuth]] ([[Single user login|SUL]] single signon) == Develop new programs == * Design the program logic * Write a [[Python]] script == Script location == === Gerrit === Folder scripts: (preinstalled scripts) <syntaxhighlight lang="bash"> pwb create_isbn_edition </syntaxhighlight> === GitHub === Download to folder scripts/userscripts: * https://github.com/geertivp/Pywikibot/blob/main/add_image_from_sdc.py === Private === Folder scripts/userscripts: * [[d:Wikidata:Wikidata curricula/Activities/Pywikibot/Missing label in target language]] (obsolete) *[[Pywikibot/Mass user mailing|Mass user mailing]] (requires <code>noratelimit</code> right) == Optional requirements == * a [[bot account]]; this is a user account with a [[bot flag]], that allows for higher transaction rates and volumes * You normally need a bot flag for all platforms. Problem: there exist more than 340 Wikipedia languages, for which you would require an individual bot flag. == Alternative tools == A combination of: * [[AutoWikiBrowser]] (AWB) on Microsoft Windows * [[Wikidata Query]] * (manual) Excel manipulation * [[OpenRefine]] (online update) * [[d:Help:QuickStatements|QuickStatements]] (copy/paste) These solutions could be much simpler to use (don't require programming, installing, or configuration tools). Can be used as a prototype, or a proof of concept for a more complicated tool. But it incurs (more) manual operations, and possibly human errors. == Related tools == * [[Wikidata Query]] * [[ListeriaBot]] == Known developers == {| class="wikitable" !Bot account !User !Platforms !Scripts |- |[[d:User:GeertivpBot|GeertivpBot]] |[[User:Geertivp|Geertivp]] |[[Wikidata]], [[Wikimedia Commons]], [[Wikipedia]] |[https://github.com/geertivp/Pywikibot GitHub] |- | |[[d:User:Magnus_Manske|Magnus Manske]] |[[Wikidata]], [[Wikimedia Commons]] |[https://magnustools.toolforge.org Magnus tools] |- |[[mw:User:Xqt|Xqt]] |Claus |Pywikibot | |} == Known problems == === Maximum retries attempted === ERROR: Error creating Van Aelst, Edit to page <nowiki>[[wikidata:-1]]</nowiki> failed: Maximum retries attempted due to maxlag without success. Problems due to maxlag too high for Pywikibot. Manual edits via the GUI still succeed normally... why? See [[Grafana]]? After one hour the problem disappeared. But still [https://grafana.wikimedia.org/d/TUJ0V-0Zk/wikidata-alerts Grafana] Max Lag > 3 s.<syntaxhighlight lang="bash"> pwb -maxlag:5 </syntaxhighlight> == See also == * [[d:Help:Pywikibot|Help:Pywikibot]] * [[mw:Manual:Pywikibot]] * [[mw:Manual:Pywikibot/Wikidata]] * [[wikidata:Wikidata:Pywikibot - Python 3 Tutorial|d:Wikidata:Pywikibot - Python 3 Tutorial]] {{Special:PrefixIndex/{{FULLPAGENAME}}/|stripprefix=1}} [[Category:Pywikibot]] qokebt1qrjljhauzkuqwep4qxh9v4lb