This module contains a set of utilities for interacting with the MediaWiki API.
Here’s an example of a common usage pattern:
>>> from mw import api
>>>
>>> session = api.Session("https://en.wikipedia.org/w/api.php")
>>>
>>> revisions = session.revisions.query(
... properties={'ids', 'content'},
... titles={"User:EpochFail"},
... direction="newer",
... limit=3
... )
>>>
>>> for rev in revisions:
... print(
... "rev_id={0}, length={1} characters".format(
... rev['revid'],
... len(rev.get('*', ""))
... )
... )
...
rev_id=190055192, length=124 characters
rev_id=276121340, length=132 characters
rev_id=276121389, length=124 characters
Represents a connection to a MediaWiki API.
Cookies and other session information is preserved.
Parameters: |
|
---|
An instance of mw.api.Pages.
An instance of mw.api.Revisions.
An instance of mw.api.RecentChanges.
An instance of mw.api.SiteInfo.
An instance of mw.api.UserContribs.
An instance of mw.api.Users.
An instance of mw.api.DeletedRevisions.
Performs a login operation. This method usually makes two requests to API – one to get a token and one to use the token to log in. If authentication fails, this method will throw an errors.AuthenticationError.
Parameters: |
|
---|---|
Returns: | The response in a json dict |
Queries deleted revisions. See https://www.mediawiki.org/wiki/API:Deletedrevs
Parameters: |
|
---|
TODO
Recent changes (revisions, page creations, registrations, moves, etc.)
Enumerate recent changes. See https://www.mediawiki.org/wiki/API:Recentchanges
Parameters: |
|
---|
A collection of revisions indexes by title, page_id and user_text. Note that revisions of deleted pages are queriable via mw.api.DeletedRevs.
Get a single revision based on it’s ID. Throws a KeyError if the rev_id cannot be found.
Parameters: |
|
---|---|
Returns: | A single rev dict |
Get revision information. See https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv
Parameters: |
|
---|---|
Returns: | An iterator of rev dicts returned from the API. |
General information about the site.
General information about the site. See https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si
Parameters: |
|
---|
A collection of revisions indexes by user.
Get a user’s revisions. See https://www.mediawiki.org/wiki/API:Usercontribs
Parameters: |
|
---|
The error code returned by the api – if available.
The error message returned by the api – if available.
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.