MediaWikiAPI Documentation¶
Here you can find the full developer API for the MediaWikiAPI project.
Contents:
Classes¶
-
class
mediawikiapi.
MediaWikiAPI
(config=None)[source]¶ -
-
category_members
(title=None, pageid=None, cmlimit=10, cmtype='page')[source]¶ Get list of page titles belonging to a category. Keyword arguments:
- title - category title. Cannot be used together with “pageid”
- pageid - page id of category page. Cannot be used together with “title”
- cmlimit - the maximum number of titles to return
- cmtype - which type of page to include. (“page”, “subcat”, or “file”)
-
geosearch
(latitude, longitude, title=None, results=10, radius=1000)[source]¶ 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
-
languages
()[source]¶ List all the currently supported language prefixes (usually ISO language code).
Can be inputted to WikipediaPage.conf 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().
-
page
(title=None, pageid=None, auto_suggest=True, redirect=True, preload=False)[source]¶ 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
Attention!
The usage of auto_suggest may provide you with different page than you searched.
For example:
page(“The Squires (disambiguation)”, auto_suggest=True) returns page with title Squires (disambiguation)
page(“The Squires (disambiguation)”, auto_suggest=False) returns page with title The Squires (disambiguation)
-
random
(pages=1)[source]¶ 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)
-
search
(query, results=10, suggestion=False)[source]¶ 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
-
suggest
(query)[source]¶ Get a Wikipedia search suggestion for query. Returns a string or None if no suggestion was found.
-
summary
(title, sentences=0, chars=0, auto_suggest=True, redirect=True)[source]¶ 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
-
-
class
mediawikiapi.
WikipediaPage
(title=None, pageid=None, redirect=True, preload=False, original_title='', request=None)[source]¶ Contains data from a Wikipedia page. Uses property methods to filter data from the raw HTML.
-
__init__
(title=None, pageid=None, redirect=True, preload=False, original_title='', request=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
backlinks
¶ List of pages that link to a given page
-
backlinks_ids
¶ List of pages ids that link to a given page
Note
It is not garanted that backlinks_ids list contains all backlinks. Sometimes the pageid is missing and only title is available, as a result len(backlinks_ids) <= len(backlinks).
-
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
-
images
¶ List of URLs of images on the page.
-
lang_title
(lang_code)[source]¶ 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)[source]¶ 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.
-
-
class
mediawikiapi.
Language
(language=None)[source]¶ Language used in mediawiki, if language is not defined English will be used
-
language
¶ Return language
-
-
class
mediawikiapi.
Config
(language=None, user_agent=None, rate_limit=None)[source]¶ Contains global configuration
-
__init__
(language=None, user_agent=None, rate_limit=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
get_api_url
(language=None)[source]¶ Return api for specified language Arguments: * language - (string or Language instance) specifying the language
-
language
¶ Return current global language
-
Exceptions¶
Global wikipedia exception and warning classes.
-
exception
mediawikiapi.exceptions.
HTTPTimeoutError
(query)[source]¶ Exception raised when a request to the Mediawiki servers times out.
-
exception
mediawikiapi.exceptions.
LanguageError
(language)[source]¶ Exception raised when a language prefix is set which is not available
-
exception
mediawikiapi.exceptions.
MediaWikiAPIException
(error)[source]¶ Base Wikipedia exception class.