Skip to main content

Wikipedia API for Python

Project description

https://travis-ci.org/goldsmith/Wikipedia.png?branch=master https://pypip.in/d/wikipedia/badge.png https://pypip.in/v/wikipedia/badge.png

Wikipedia is a Python library that makes it easy to access and parse data from Wikipedia.

Search Wikipedia, get article summaries, get data like links and images from a page, and more. Wikipedia wraps the MediaWiki API so you can focus on using Wikipedia data, not getting it.

>>> import wikipedia
>>> print wikipedia.summary("Wikipedia")
# Wikipedia (/wkpidi/ or /wkipidi/ WIK-i-PEE-dee-) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...

>>> wikipedia.search("Barack")
# [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']

>>> ny = wikipedia.page("New York")
>>> ny.title
# u'New York'
>>> ny.url
# u'http://en.wikipedia.org/wiki/New_York'
>>> ny.content
# u'New York is a state in the Northeastern region of the United States. New York is the 27th-most exten'...
>>> ny.links[0]
# u'1790 United States Census'

>>> wikipedia.set_lang("fr")
>>> wikipedia.summary("Facebook", sentences=1)
# Facebook est un service de rseautage social en ligne sur Internet permettant d'y publier des informations (photographies, liens, textes, etc.) en contrlant leur visibilit par diffrentes catgories de personnes.

Note: this library was designed for ease of use and simplicity, not for advanced use. If you plan on doing serious scraping or automated requests, please use Pywikipediabot (or one of the other more advanced Python MediaWiki API wrappers), which has a larger API, rate limiting, and other features so we can be considerate of the MediaWiki infrastructure.

Installation

To install Wikipedia, simply run:

$ pip install wikipedia

Wikipedia is compatible with Python 2.6+ (2.7+ to run unittest discover) and Python 3.3+.

Documentation

Read the docs at https://wikipedia.readthedocs.org/en/latest/.

To run tests, clone the respository on GitHub, then run:

$ pip install -r requirements.txt
$ python -m unittest discover tests/ '*test.py'

in the root project directory.

To build the documentation yourself, after installing requirements.txt, run:

$ pip install sphinx
$ cd docs/
$ make html

License

MIT licensed. See the LICENSE file for full details.

Credits

  • wiki-api by @richardasaurus for inspiration

  • @nmoroze and @themichaelyang for feedback and suggestions

  • The Wikimedia Foundation for giving the world free access to data

Project details


Download files

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

Source Distribution

wikipedia-1.0.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

wikipedia-1.0.0.macosx-10.8-intel.exe (81.7 kB view details)

Uploaded Source

File details

Details for the file wikipedia-1.0.0.tar.gz.

File metadata

  • Download URL: wikipedia-1.0.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wikipedia-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f903a9abe75d07821ee15f6eb0a64c759b1020abbff86f3507bc3be6b7f685bf
MD5 c4eadf6c998d380507c1a9eaad5e24e0
BLAKE2b-256 2ea2fb0068d7c02e98e9a7c6b3d723097042d7a2058a091fdaacd6168f820b62

See more details on using hashes here.

File details

Details for the file wikipedia-1.0.0.macosx-10.8-intel.exe.

File metadata

File hashes

Hashes for wikipedia-1.0.0.macosx-10.8-intel.exe
Algorithm Hash digest
SHA256 4b8454e7464111fe406826e763cdf3030aae56113c812d60627f1fa7ab0a9c06
MD5 96c2f2c08a5b88a8aeb46d102b06bc65
BLAKE2b-256 895e3719680824ebbc39c6825d7d4e3ca04c3f67ee5ca60a5ca76a24263a696e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page