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

Installing Python
To use Pywikibot you must first install Python.

Windows
 Start PowerShell Install Scoop Run the following commands in PowerShell:  

macOS
 Open Terminal</li> Install Homebrew</li> Install Python by pasting the following into Terminal and hitting Enter: </li> </ol>

Installing and configuring Pywikibot
 Install Pywikibot: </li> Create a base directory for Pywikibot, for example:

You can name the directory whatever you'd like and locate it wherever you please. </li> 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> Append the following line to the  file that was created in your PWB base directory in the previous step. </li> Download the Pywikibot scripts and move them to a subfolder named  in your PWB base directory.</li> Log in with Pywikibot: </li> </ol>

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

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. For example:

See for a list of scripts. 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 editing the next 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 replaaced 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.