MediaWikiAPI Documentation¶
Here you can find the full developer API for the MediaWikiAPI project.
Contents:
Functions and Classes¶
-
mediawikiapi.
search
(query, results=10, suggestion=False)¶ Do a Wikipedia search for query.
Keyword arguments:
- results - the maxmimum number of results returned
- suggestion - if True, return results and suggestion (if any) in a tuple
-
mediawikiapi.
suggest
(query)¶ Get a Wikipedia search suggestion for query. Returns a string or None if no suggestion was found.
-
mediawikiapi.
summary
(query, sentences=0, chars=0, auto_suggest=True, redirect=True)¶ Plain text summary of the page.
Note
This is a convenience wrapper - auto_suggest and redirect are enabled by default
Keyword arguments:
- sentences - if set, return the first sentences sentences (can be no greater than 10).
- chars - if set, return only the first chars characters (actual text returned may be slightly longer).
- auto_suggest - let Wikipedia find a valid page title for the query
- redirect - allow redirection without raising RedirectError
-
mediawikiapi.
page
(title=None, pageid=None, auto_suggest=True, redirect=True, preload=False)¶ Get a WikipediaPage object for the page with title title or the pageid pageid (mutually exclusive).
Keyword arguments:
- title - the title of the page to load
- pageid - the numeric pageid of the page to load
- auto_suggest - let Wikipedia find a valid page title for the query
- redirect - allow redirection without raising RedirectError
- preload - load content, summary, images, references, and links during initialization
-
mediawikiapi.
geosearch
(latitude, longitude, title=None, results=10, radius=1000)¶ Do a wikipedia geo search for latitude and longitude using HTTP API described in http://www.mediawiki.org/wiki/Extension:GeoData
Arguments:
- latitude (float or decimal.Decimal)
- longitude (float or decimal.Decimal)
Keyword arguments:
- title - The title of an article to search for
- results - the maximum number of results returned
- radius - Search radius in meters. The value must be between 10 and 10000
-
class
mediawikiapi.
WikipediaPage
(title=None, pageid=None, redirect=True, preload=False, original_title='')¶ Contains data from a Wikipedia page. Uses property methods to filter data from the raw HTML.
-
categories
¶ List of categories of a page.
-
content
¶ Plain text content of the page, excluding images, tables, and other data.
-
coordinates
¶ Tuple of Decimals in the form of (lat, lon) or None
-
html
()¶ Get full page HTML.
Warning
This can get pretty slow on long pages.
-
images
¶ List of URLs of images on the page.
-
lang_title
(lang_code)¶ Get the title in specified language code Returns None if lang code or title isn’t found, otherwise returns a string with title. Raise LanguageException if language doesn’t exists
-
links
¶ List of titles of Wikipedia page links on a page.
Note
Only includes articles from namespace 0, meaning no Category, User talk, or other meta-Wikipedia pages.
-
parent_id
¶ Revision ID of the parent version of the current revision of this page. See
revision_id
for more information.
-
references
¶ List of URLs of external links on a page. May include external links within page that aren’t technically cited anywhere.
-
revision_id
¶ Revision ID of the page.
The revision ID is a number that uniquely identifies the current version of the page. It can be used to create the permalink or for other direct API calls. See Help:Page history for more information.
-
section
(section_title)¶ Get the plain text content of a section from self.sections. Returns None if section_title isn’t found, otherwise returns a whitespace stripped string.
This is a convenience method that wraps self.content.
Warning
Calling section on a section that has subheadings will NOT return the full text of all of the subsections. It only gets the text between section_title and the next subheading, which is often empty.
-
sections
¶ List of section titles from the table of contents on the page.
-
summary
¶ Plain text summary of the page.
-
-
mediawikiapi.
languages
()¶ List all the currently supported language prefixes (usually ISO language code).
Can be inputted to set_lang to change the Mediawiki that wikipedia requests results from.
Returns: dict of <prefix>: <local_lang_name> pairs. To get just a list of prefixes, use wikipedia.languages().keys().
-
mediawikiapi.
set_lang
(lang)¶
-
mediawikiapi.
random
(pages=1)¶ Get a list of random Wikipedia article titles.
Note
Random only gets articles from namespace 0, meaning no Category, User talk, or other meta-Wikipedia pages.
Keyword arguments:
- pages - the number of random pages returned (max of 10)
-
mediawikiapi.
donate
()¶ Open up the Wikimedia donate page in your favorite browser.
Exceptions¶
Global wikipedia exception and warning classes.
-
exception
mediawikiapi.exceptions.
DisambiguationError
(title, may_refer_to)¶ Exception raised when a page resolves to a Disambiguation page.
The options property contains a list of titles of Wikipedia pages that the query may refer to.
Note
options does not include titles that do not link to a valid Wikipedia page.
-
exception
mediawikiapi.exceptions.
HTTPTimeoutError
(query)¶ Exception raised when a request to the Mediawiki servers times out.
-
exception
mediawikiapi.exceptions.
LanguageError
(language)¶ Exception raised when a language prefix is set which is not available
-
exception
mediawikiapi.exceptions.
MediaWikiAPIException
(error)¶ Base Wikipedia exception class.
-
exception
mediawikiapi.exceptions.
PageError
(pageid=None, *args)¶ Exception raised when no Wikipedia matched a query.
-
exception
mediawikiapi.exceptions.
RedirectError
(title)¶ Exception raised when a page title unexpectedly resolves to a redirect.