Waldir Pimenta edited this page Mar 25, 2015 · 5 revisions
Clone this wiki locally

A Site object represents a MediaWiki site with a particular hostname, such as the English Wikipedia with hostname Typical initialization of a Site:

site = mwclient.Site('')

Do not include the leading http://. By default Site assumes that api.php is located at path /w/ (e.g. If the site you are connecting to places it in a different location, you must specify this (path must end in a /):

site = mwclient.Site('', path='/')
site = mwclient.Site('', path='/apps/mediawiki/mwclient/')

Typically api.php is in the same location as index.php. If you edit or view source of a page, you should see the path of index.php in the URL (e.g.

By default, mwclient will allow you to view but not edit pages unless you are logged in. It is good practice to always log in to an account when editing using a bot, so that it can be blocked if it malfunctions:

site.login('username', 'password')

This will raise LoginError upon failure.

Site provides access to any page by name as a Page object via the Pages object:

page = site.Pages['Apple']
template = site.Pages['Template:Stub']
wppage = site.Pages['Wikipedia:Five pillars']
mwpage = site.Pages['MediaWiki:Aboutsite']
image = site.Pages['Image:Wiki.png']  # This will return an [[Image]] object
category = site.Pages['Category:People']  # This will return a [[Category]] object

For images or categories, you can alternatively use the Images or Categories object and omit the namespace prefix:

image2 = site.Images['Wiki.png'] # The same image as above
category2 = site.Categories['People'] # The same category as above

Method reference

Raw API interface

Internal methods

Data member reference

This page was originally imported from the old mwclient wiki at SourceForge. The imported version was dated from 09:10, 25 November 2011, and its only editor was Derrickcoetzee (@dcoetzee).