Guidelines:Pywikibot

Pywikibot (PWB) is a collection of Python scripts that allows users to perform against several pages with a single command.

Setting up a bot account
 If you haven't already, create a bot account separate from your normal account. Go to Special:BotPasswords/PWB and tick the following checkboxes. Some checkboxes may only be available to admins—tick whichever ones are available to you.  Hit the  button and record the password shown on the next page. 
 * High-volume editing
 * Edit existing pages
 * Edit protected pages
 * Create, edit, and move pages
 * Upload new files
 * Upload, replace, and move files
 * Patrol changes to pages
 * Rollback changes to pages
 * Delete pages, revisions, and log entries

Windows
 Install git (the default options in the setup wizard are fine) Start PowerShell In PowerShell, type  and hit Enter to open the latest version of Python in the Microsoft Store. Install this version. Download Pywikibot: </li> Change to the  base directory: </li> Install Pywikibot's dependencies: </li> </ol>

macOS
 Open Terminal</li> Install Homebrew</li> Install Python by pasting the following into Terminal and hitting Enter: </li> Install git: </li> Download Pywikibot: </li> Change to the  base directory: </li> Install Pywikibot's dependencies: </li> </ol>

Configuring Pywikibot
 Create a for : </li> Create user config files: You will be prompted to fill in some information. For each prompt, type the following and hit Enter:

<dl> <dt>Family</dt><dd> </dd> <dt>Site code</dt><dd> </dd> <dt>Username</dt><dd>Enter your bot account's username.</dd> <dt>Do you want to add any other projects?</dt><dd> </dd> <dt>Do you want to add a BotPassword?</dt><dd> </dd> <dt>BotPassword's "bot name"</dt><dd> </dd> <dt>BotPassword's "password" for "PWB"</dt><dd>Paste the BotPassword created above.</dd> <dt>Do you want to select framework setting sections?</dt><dd> </dd> <dt>Do you want to select scripts setting sections?</dt><dd> </dd> </dl> </li> Log in with Pywikibot: </li> </ol>

The login is successful if the following message appears: Logged in on zeldawiki:en as

The above message may be preceded by the following errors and warnings which can be ignored:

Using Pywikibot
Pywikibot only works from the Pywikibot base directory. Whenever you open a new terminal session, you must change to the base directory:

See for the list of scripts you can run. To learn more about how to use a script, you can type the following command:

Typing simply  will show you command options available for all scripts.

By default, PWB waits for 10 seconds before saving each page. To remove this wait period, add  to the command.

Example commands
Below are some examples of some useful Pywikibot commands.

Null-editing all pages using a certain template
The  namespace prefix can be omitted.

Replacing text for all pages in a category
Where  is a file in the PWB base directory that looks something like this:

Here  would be replaced with   and   would be replaced with.

This command supports regex with the  option. Escape special regex characters with a backslash. For example,  will match pipe characters. Failing to escape pipe characters when using regex replacements can be quite disastrous.

The script will show you each edit and ask you to confirm before saving each page. At any point you can tell it to save the rest of the pages without confirmation.

Uploading all files in a folder
Where  is a file in the PWB base directory containing the Template:FileInfo that will be added to all the uploads. Fill in whichever fields apply to all files—you can fill in the rest once the files have been uploaded.