Skip to main content

Wikipedia tools (for Humans)

Project description

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

This package is intended to make it as easy as possible to get data from MediaWiki instances, expose more Wikidata, and extend Wikimedia APIs just for kicks. We say “(for Humans)” because that is a goal. Questions, feedback, and especially contributions are welcome!


$ pip install wptools


>>> import wptools
>>> page ='Gandhi')
>>> page.get() (query) Gandhi (parse) 19379 (wikidata) Q1001 (labels) Q1280678|P535|Q18338317|P434|Q1860|P376... (labels) P18|P19|P1066|P509|P345|Q16382|P1006|P3... (labels) Q2140674|Q1282294|Q21200566|P409|Q26490... (labels) P3417|P4431|P2949|P69|Q129286|Q9441|P42... (restbase) /page/summary/Mahatma_Gandhi (imageinfo) File:Portrait Gandhi.jpg|File:MKGandhi.jpg
Mahatma Gandhi (en) data
  aliases: <list(10)> M K Gandhi, Mohandas Gandhi, Bapu, Gandhi, M...
  claims: <dict(106)> P646, P535, P906, P434, P648, P3762, P1273, ...
  description: <str(67)> pre-eminent leader of Indian nationalism ...
  exhtml: <str(1144)> <p>Mahātmā <b>Mohandas Karamchand Gandhi</b>...
  exrest: <str(907)> Mahātmā Mohandas Karamchand Gandhi (; Hindust...
  extext: <str(2999)> Mahātmā **Mohandas Karamchand Gandhi** ( ; H...
  extract: <str(3292)> <p>Mahātmā <b>Mohandas Karamchand Gandhi</b...
  image: <list(6)> {'kind': 'query-pageimage', u'descriptionshortu...
  infobox: <dict(25)> known_for, other_names, image, signature, bi...
  iwlinks: <list(10)>,...
  label: Mahatma Gandhi
  labels: <dict(163)> Q1280678, P535, Q18338317, Q131149, P434, Q1...
  length: 262,058
  links: <list(500)> 10 Janpath, 14th Dalai Lama, 1915 Singapore M...
  modified: <dict(2)> wikidata, page
  pageid: 19379
  parsetree: <str(330951)> <root><template><title>Redirect</title>...
  random: Salt
  redirected: <list(1)> {u'to': u'Mahatma Gandhi', u'from': u'Gandhi'}
  redirects: <list(53)> {u'ns': 0, u'pageid': 55342, u'title': u'M...
  requests: <list(9)> query, parse, wikidata, labels, labels, labe...
  title: Mahatma_Gandhi
  watchers: 1,770
  what: human
  wikibase: Q1001
  wikidata: <dict(105)> profile ID (P2600), National Libr...
  wikitext: <str(260607)> {{Redirect|Gandhi}}{{pp-move-indef}}{{pp...
>>> page.get_more() (querymore) Gandhi
Mahatma Gandhi (en) data
  categories: <list(68)> Category:1869 births, Category:1948 death...
  contributors: 2,608
  files: <list(52)> File:Aum Om red.svg, File:Commons-logo.svg, Fi...
  languages: <list(167)> {u'lang': u'af', u'title': u'Mahatma Gand...
  views: 24,565


See our wiki.

Please enjoy!

@siznax 👹

Release History

0.4.2 (2017-11-20)

  • Getting ALL Wikidata (#56)
  • Surfaced redirects, disambiguation links (#25)
  • Increased test coverage to 95%, pylint score 10.0
  • Added more page data, split off expensive queries
  • Implemented basic category and site functionality
  • Changed page._WIKIPROPS to wikidata.LABELS
  • Refactored attributes to only cache, data, flags, params
  • Unified Wikimedia APIs access pattern via wptools.core

0.3 (2017-08-13)

  • Implemented general RESTBase /page/ access (#67)
  • Merged @rikima’s contrib plus py3 patch (#66)
  • Made, query(), response() methods useable
  • Improved wiki documentation (see Actions, Attributes)

0.2.3 (2017-04-17)

  • Merge @aplz improvement: fetch full lists in infobox values (#62)
  • Put HTML extract with wikilinks into ‘exhtml’
  • Fix AttributeError bug (#47)
  • Refactoring fixes

0.2 (2016-11-06)

  • Many fixes/improvements with help of @seansay (thank you!)
  • Raise LookupError on API missing page/title
  • Consolidated images and caches
  • Support get_query() by pageid
  • Support proxy, timeout on all API entrypoints
  • Support for language variants (e.g. variant=’zh-cn’)
  • Support for non-https wikis via wiki=’
  • Automatically get_imageinfo() via MediaWiki API:Imageinfo
  • moved to wiki

0.1.7 (2016-09-20)

  • Minor fixes
  • Provide local SSL certs with python-certifi
  • Enabled extending Wikidata properties
  • Improved cache checking

0.1.4 (2016-09-06)

  • Python 3 support!
  • Implemented get_claims()
  • Patch get_rest() path, tests/test_advanced
  • Implemented get_wikidata() by title, lang
  • Geo coordinates Property:P625 from Wikidata
  • Added RESTBase support, lead attribute
  • Made the atomic object

0.1.0 (2016-08-25)

  • Many fixes, enhancements.
  • Much testing of random (title, lang, and wiki).
  • Allow chaining get_s or just get().
  • Enabled full-hydration from wikibase only.
  • Block further requests on fatal error.
  • Get 240x thumbnails instead of default 50x.
  • Harmonized silent and verbose arguments.
  • Mock-up tests/
  • Made a knowledge base.
  • Use _humans_ in README examples. ;-)

0.0.5 (2016-08-23)

  • Major re-write.
  • Exposed core.WPTools as entrypoint.
  • Added get_parse(), get_query(), and get_wikidata().
  • Added get(self) to query all APIs.
  • Added show(self) method to display fetched attrs.
  • Show instance attributes after each request.
  • Ignore requests if attrs will not be updated.
  • Enabled language support across APIs.
  • Gets random article if no arguments.
  • CLI scripts and tests disabled pending update.

0.0.4 (2016-08-16)

  • Added wptools.lead.
  • Added safe_exit() to CLI scripts.
  • Removed a fair amount of unused code.

0.0.3 (2016-08-12)

  • Implemented wptools.image choices.
  • Added wptools.api to simplify python i/f and CLI scripts.
  • Merged @0x9900’s CLI dist fixes.
  • A little more test coverage.
  • Starting to look like a legit module.

0.0.1 (2015)

  • Still better than alternatives for working with articles.

0.0.0 (2012)

  • It seems to work!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wptools, version 0.4.2
Filename, size File type Python version Upload date Hashes
Filename, size wptools-0.4.2-py2.py3-none-any.whl (33.3 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size wptools-0.4.2.tar.gz (27.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page