User:Lalit97/Sandbox/My first Pywikibot tool

From Wikitech
Jump to navigation Jump to search


Pywikibot is a Python library and collection of tools that automate work on MediaWiki sites. Originally designed for Wikipedia, it is now used throughout the Wikimedia Foundation's projects and on many other MediaWiki wikis.

The project started in 2002 and is currently on core version 3.0. It features full API usage and is up-to-date with new MediaWiki features and a Pythonic package layout. But it also works with older installations of MediaWiki 1.19 or higher.

Pywikibot supports Microsoft Windows, OS X and Linux when used with a compatible version of Python. It should also work on any other operating system that has a compatible version of Python installed. To check whether you have Python installed and to find its version, just type "python" at the CMD or shell prompt. Python 2.7.4 or higher or Python 3.4 or higher is required to run the bot but 3.5 or higher is recommended.

The guide will teach you how to:

Getting started



  • Basic knowledge of Python
  • Basic knowledge of SSH
  • Basic knowledge of the Unix command line
  • Familiarity with OAuth terminology would be nice but not required


Steps to completion

  • Create a new tool account
  • Create a basic Pywikibot webservice
  • Add a configuration file
  • Add support for OAuth authentication

Step-by-step guide

Step 1: Create a new tool account

  1. Create a new tool account.
    • For the examples in this tutorial, <TOOL NAME> is used to indicate places where your unique tool name is used in another command.
  2. SSH to
    • If your local username is different from your shell account name on Toolforge, you will need to include your Toolforge shell account name in your ssh command (i.e. <shell_username>
  3. Run become <TOOL NAME> to change to the tool user.

Step 2: Create your Pywikibot Tool account

In addition to your own Toolforge account, you also need to create a Tool acoount for your Pywikibot tool.

  1. Navigate to the Create Tool Account page in the Toolforge admin console.
  2. Enter a Unique Tool Name for your tool account.
    Do not prefix your tool name with tools. as this prefix will cause errors.

Note: If you only recently received access to the tools project, you may get an error about appropriate credentials. Log out and back in to fix the issue.

Within a minute or two, Toolforge creates the Tool account and grants you access. If you were logged in through ssh when you created the Tool account, you must log off and log in again

Step 3: Access your Pywikibot tool

After you create your Pywikibot's tool account, you can log into your tool project with SSH.

$ ssh <unix shell username>

From the command line, switch to your tool account:

become <toolname>

You should see the command prompt change to:


Now, you can install Pywikibot.

Step 4: Install Pywikibot

Using your tool account, do the following:

  1. Use git to download Pywikibot:
    git clone --recursive --branch stable pywikibot-core
    cd pywikibot-core
  2. Set up your bot for selected wikis by running:

Choose a license

Pywikibot comes with an MIT LICENSE file. Make sure to choose a license for your tool early on. Also see, Help:Tool_Labs/Developing#Licensing_your_source_code


Set up a webpage for your tool

You can add webpage for your tool under For example, Once you set up a webpage for your tool, the Tool list will link to it.

To set up webpage for you tool:

  1. Log in with your Tool account.
  2. Create a ~/public_html directory.
  3. Create ~/public_html/index.html.
  4. Start the web service:
$ webservice start

Communication and support

We communicate and provide support through several primary channels. Please reach out with questions and to join the conversation.

Communicate with us
Way Connect Best for
Phabricator Workboard #Cloud-Services Task tracking and bug reporting
IRC Channel #wikimedia-cloud connect
Telegram bridge
mattermost bridge
General discussion and support
Mailing List cloud@ Information about ongoing initiatives, general discussion and support
Announcement emails cloud-announce@ Information about critical changes (all messages mirrored to cloud@)
News wiki page News Information about major near-term plans
Cloud Services Blog Clouds & Unicorns Learning more details about some of our work
Wikimedia Technical Blog News and stories from the Wikimedia technical movement

See also