-
Dan Michael O. Heggø authored
simplejson is now a requirement installed by easy_install, pip or other toos. ReadMe was converted from MarkDown to reStructuredText to make it usable at PyPI while still being supported by GitHub.
Dan Michael O. Heggø authoredsimplejson is now a requirement installed by easy_install, pip or other toos. ReadMe was converted from MarkDown to reStructuredText to make it usable at PyPI while still being supported by GitHub.
mwclient
Mwclient is a client to the MediaWiki API which provides access to most
API functionality. It depends heavily on Bob Ippolito's SimpleJSON,
requires Python 2.4 and supports MediaWiki 1.11 and above. For functions not
available in the current MediaWiki, a MediaWikiVersionError
is raised.
This framework was written by Bryan Tong Minh, who released the latest stable version 0.6.5 at 6 May 2011. The current development version can be installed directly off github:
$ pip install git+git://github.com/btongminh/mwclient.git
Please see release notes for a list of changes.
Implementation notes
Most properties and generators accept the same parameters as the API, without their two letter prefix. Exceptions to this rule:
-
Image.imageinfo
is the imageinfo of the latest image. Earlier versions can be fetched usingimagehistory()
-
Site.all*
: parameter[ap]from
renamed tostart
-
categorymembers
is implemented asCategory.members
-
deletedrevs
isdeletedrevisions
-
usercontribs
isusercontributions
- First parameters of
search
andusercontributions
aresearch
anduser
respectively
Properties and generators are implemented as Python generators.
Their limit parameter is only an indication of the number of items in one chunk.
It is not the total limit.
Doing list(generator(limit = limit))
will return ALL items of generator,
and not be limited by the limit value.
Default chunk size is generally the maximum chunk size.
HTTPS
To use https, specify the host as a tuple in the form of ('https', hostname)
.
Example
For more information, see REFERENCE.md.
# Initialize Site object
import mwclient
site = mwclient.Site('commons.wikimedia.org')
site.login(username, password) # Optional
# Edit page
page = site.Pages['Commons:Sandbox']
text = page.edit()
print 'Text in sandbox:', text.encode('utf-8')
page.save(text + u'\nExtra data', summary = 'Test edit')
# Printing imageusage
image = site.Images['Example.jpg']
print 'Image', image.name.encode('utf-8'), 'usage:'
for page in image.imageusage():
print 'Used:', page.name.encode('utf-8'), '; namespace', page.namespace
print 'Image info:', image.imageinfo
# Uploading a file
site.upload(open('file.jpg'), 'destination.jpg', 'Image description')
# Listing all categories (don't do this in reality)
for category in site.allcategories():
print category