Skip to main content

Wikipedia API on Python

Project description

PyPI version Version Build Status GitHub Issues License [Docs

MediaWikiAPI 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 <https://www.mediawiki.org/wiki/API>__ so you can focus on using Wikipedia data, not getting it.

>>> from mediawikiapi import MediaWikiAPI
>>> mediawikiapi = MediaWikiAPI()
>>> print mediawikiapi.summary("Wikipedia")
# Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation...

>>> mediawikiapi.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 = mediawikiapi.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'

>>> mediawikiapi.conf.language = "fr"
>>> mediawikiapi.summary("Facebook", sentences=1)
# Facebook est un service de réseautage social en ligne sur Internet permettant d'y publier des informations (photographies, liens, textes, etc.) en contrôlant leur visibilité par différentes catégories de personnes.

Installation

To install MediaWikiAPI, simply run:

pip install mediawikiapi

MediaWikiAPI is compatible with Python 3 and Python 2.7.

Documentation

The documentation is available here Changelog could be find in the documentation.

To run tests, clone the repository on GitHub <https://github.com/lehinevych/MediaWikiAPI>__, then run:

pip install -r requirements.txt
bash runtests  # will run tests for python and python3
python -m unittest discover tests/ '*test.py'  # manual style

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 <https://github.com/lehinevych/MediaWikiAPI/blob/master/LICENSE>__ for full details.

Credits

  • @goldsmith for making such a fantastic library to fork

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

mediawikiapi-1.1.0.tar.gz (12.5 kB view details)

Uploaded Source

File details

Details for the file mediawikiapi-1.1.0.tar.gz.

File metadata

  • Download URL: mediawikiapi-1.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mediawikiapi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9bc868756783f9813f6f234feb34df33a3c923834ac273864a619a0522c18266
MD5 515d7df09e78986570d9e6eda63d0717
BLAKE2b-256 865b4a3ebb548a7a65d5d89d2c24ada48601e5b9d196f7d268c5d37ab4889824

See more details on using hashes here.

Supported by

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