From Wikibooks, open books for an open world
Jump to: navigation, search


Before you run any of the programs, you need to create a file named in your pywikipedia directory. You can create it manually (it needs at least two or three variables configured, see below) or run the script by typing python in the command line shell and hit ENTER. That helps to complete this process.

For Wikimedia projects[edit]

Open a text editor (e.g. Notepad in Windows) and save the text file as, in the pywikipedia folder.

Add the following lines to

Code Explanation
family = 'wikipedia'
mylang = 'en'

xx is the code for the language code you are working on, "en" is English[1]. Family is the project name[2].

usernames['wikipedia']['en'] = u'ExampleBot'


Your file needs to specify the bot's username.

In this example, the user is working on English Wikipedia, and has created a bot account with the username "ExampleBot".


usernames['wikipedia']['de'] = u'BeispielBot'
usernames['wikipedia']['en'] = u'ExampleBot'
usernames['wiktionary']['de'] = u'BeispielBot'


If you are working on more than one Wikimedia project, you can also add several usernames.


console_encoding = 'utf-8'
textfile_encoding = 'unicode_escape'

(Optional, and rarely needed)

If this is the encoding used by your system. Always try without first.

Now save again.

For non-Wikimedia wikis[edit]

Main Page: Pywikibot/Use on non-WMF wikis


  1. If you want to work with more than one language, choose the most common one. You can override this on the command line by using -lang:zh parameter.
  2. Meta uses 'meta' for both language code and wiki family, Commons uses 'commons' for both, and Testwiki uses 'test' for both. You can override this on the command line by using -family:wikibooks.
  3. The 'u' in front of the username stands for Unicode. The 'u' is required if your username contains non-ASCII characters.