Wikipedia tools (for Humans): easily extract data from Wikipedia, Wikidata, and other MediaWikis
Wikipedia tools (for Humans) ============================
.. image:: https://img.shields.io/pypi/v/wptools.svg :target: https://pypi.python.org/pypi/wptools/
.. image:: https://travis-ci.org/siznax/wptools.svg?branch=master :target: https://travis-ci.org/siznax/wptools
.. image:: https://coveralls.io/repos/github/siznax/wptools/badge.svg?branch=master :target: https://coveralls.io/github/siznax/wptools
Python and command-line MediaWiki access for Humans
- get page extracts, image, Infobox data, Wikidata, and more
- get a random page, category, or site
- get page statistics
- get category members
- get site info and stats
- get data in any language
Install
.. code-block:: bash
$ pip install wptools ✨🦄✨
Example
.. code-block:: python
>>> import wptools
Get a page object:
.. code-block:: python
>>> page = wptools.page('Gandhi')
Get API:Query_ data:
.. _API:Query: https://www.mediawiki.org/wiki/API:Query
.. code-block:: python
>>> page.get_query() en.wikipedia.org (query) Gandhi en.wikipedia.org (imageinfo) File:Portrait Gandhi.jpg Mahatma Gandhi (en) data { aliases: Mahātmā Mohandas Karamchand Gandhi {u'size': 2951123, 'kind': 'query-pageimage', u... label: Mahatma Gandhi length: 262,790 links: Get .. _ .. code-block:: python >>> page.get_parse() en.wikipedia.org (parse) Gandhi en.wikipedia.org (imageinfo) File:MKGandhi.jpg Mahatma Gandhi (en) data { image: Get Wikidata_: .. _Wikidata: https://www.wikidata.org/w/api.php .. code-block:: python >>> page = wptools.page(wikibase='Q1001') >>> page.get_wikidata() www.wikidata.org (wikidata) Q1001 www.wikidata.org (labels) Q1280678|P535|P434|Q1860|P3762|Q668|P12... www.wikidata.org (labels) P119|Q1930187|P691|P18|P19|P1066|P509|P... www.wikidata.org (labels) Q6512732|Q1568|P972|Q84|P1430|P31|Q2140... www.wikidata.org (labels) P1576|Q4964182|P1368|P140|Q22336956|P12... en.wikipedia.org (imageinfo) File:Portrait Gandhi.jpg Mahatma Gandhi (en) data { aliases: Get RESTBase_ data: .. _RESTBase: https://www.mediawiki.org/wiki/RESTBase .. code-block:: python >>> page.get_restbase('/page/summary/') en.wikipedia.org (restbase) /page/summary/Gandhi Mahatma Gandhi (en) data { description: Mahātmā Mohandas Karamchand Gandhi... exrest: Get all the things (at once): .. code-block:: python >>> page.get() en.wikipedia.org (query) Gandhi en.wikipedia.org (parse) 19379 www.wikidata.org (wikidata) Q1001 www.wikidata.org (labels) Q1280678|P535|P434|Q1860|P3762|Q668|P12... www.wikidata.org (labels) P119|Q1930187|P691|P18|P19|P1066|P509|P... www.wikidata.org (labels) Q6512732|Q1568|P972|Q84|P1430|P31|Q2140... www.wikidata.org (labels) P1576|Q4964182|P1368|P140|Q22336956|P12... en.wikipedia.org (restbase) /page/summary/Mahatma_Gandhi en.wikipedia.org (imageinfo) File:MKGandhi.jpg|File:Portrait Gandhi.jpg Mahatma Gandhi (en) data { aliases: Mahātmā Mohandas Karamchand Gandhi... exrest: Mahātmā Mohandas Karamchand Gandhi {u'size': 2951123, 'kind': 'query-pageimage', u... infobox: Get more (expensive) data: .. code-block:: python >>> page.get_more() en.wikipedia.org (querymore) Gandhi Mahatma Gandhi (en) data { categories: Get data in .. _ .. code-block:: python >>> page = wptools.page(lang='zh') zh.wikipedia.org (random) 🍰 哈莉特·塔布曼 (zh) data { pageid: 211070 title: 哈莉特·塔布曼 } Get data from .. .. code-block:: python >>> page = wptools.page(wiki='en.wikiquote.org') en.wikiquote.org (random) 🍪 Malala_Yousafzai (en) { pageid: 146817 title: Malala_Yousafzai } Documentation See our wiki_. Please enjoy! @siznax 👹 .. _contributions: https://github.com/siznax/wptools/blob/master/CONTRIBUTING.md .. _goal: http://docs.python-requests.org/en/master/user/intro/ .. _wiki: https://github.com/siznax/wptools/wiki M K Gandhi, Mohandas Gandhi, Bapu, Gandhi, M... assessments:
10 Janpath, 14th Dalai Lama, 1915 Singapore M... modified:
{u'to': u'Mahatma Gandhi', u'from': u'Gandhi'} redirects:
{u'ns': 0, u'pageid': 55342, u'title': u'M... requests:
query, imageinfo title: Mahatma Gandhi url: https://en.wikipedia.org/wiki/Mahatma_Gandhi urlraw: https://en.wikipedia.org/wiki/MahatmaGandhi?action=raw watchers: 1,811 wikibase: Q1001 wikidata_url: https://www.wikidata.org/wiki/Q1001 }
API:Parse_ data:API:Parse: https://www.mediawiki.org/wiki/API:Parse {u'size': 2951123, 'kind': 'parse-image', u'des... infobox:
https://biblio.wiki/wiki/MohandasK.Gandhi,... pageid: 19379 parsetree:
parse, imageinfo title: Mahatma Gandhi wikibase: Q1001 wikidata_url: https://www.wikidata.org/wiki/Q1001 wikitext:
M K Gandhi, Mohandas Gandhi, Bapu, Gandhi, M... claims:
{u'size': 2951123, 'kind': 'wikidata-image', u'... label: Mahatma Gandhi labels:
wikidata, labels, labels, labels, labels, im... title: Mahatma_Gandhi what: human wikibase: Q1001 wikidata:
{'kind': 'restbase-original', u'width': 2024, '... pageid: 19379 requests:
restbase title: Mahatma_Gandhi url: https://en.wikipedia.org/wiki/Gandhi url_raw: https://en.wikipedia.org/wiki/Gandhi?action=raw }
M K Gandhi, Mohandas Gandhi, Bapu, Gandhi, M... assessments:
https://biblio.wiki/wiki/MohandasK.Gandhi,... label: Mahatma Gandhi labels:
10 Janpath, 14th Dalai Lama, 1915 Singapore M... modified:
{u'to': u'Mahatma Gandhi', u'from': u'Gandhi'} redirects:
{u'ns': 0, u'pageid': 55342, u'title': u'M... requests:
query, parse, wikidata, labels, labels, labe... title: Mahatma_Gandhi url: https://en.wikipedia.org/wiki/Mahatma_Gandhi urlraw: https://en.wikipedia.org/wiki/MahatmaGandhi?action=raw watchers: 1,811 what: human wikibase: Q1001 wikidata:
Category:1869 births, Category:1948 death... contributors: 2,606 files:
File:Aum Om red.svg, File:Commons-logo.svg, Fi... languages:
{u'lang': u'af', u'title': u'Mahatma Gand... pageid: 19379 redirected:
{u'to': u'Mahatma Gandhi', u'from': u'Gandhi'} requests:
querymore title: Mahatma Gandhi views: 19,242 }
another language_:another language: https://github.com/siznax/wptools/wiki/Language-Codesanother wiki_:another wiki: https://meta.wikimedia.org/wiki/Listof_Wikipedias