Skip to main content

Wikipedia API on Python

Project description

MediaWikiAPI

PyPI version Version Python package 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 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 (state)")
>>> ny.title
# u'New York (state)'
>>> ny.url
# u'http://en.wikipedia.org/wiki/New_York_(state)'
>>> ny.content
# u'New York is a state in the northeastern United States. New York was one of the original thir'...
>>> ny.links[0]
# u'1790 United States Census'

>>> mediawikiapi.config.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.

Changelog

Changelog could be find in the documentation.

Documentation

The documentation is available here

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

poetry install 
poetry build
poetry run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=mediawikiapi

in the root project directory.

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

pip install sphinx
cd docs/
make html

To run formatter and mypy run:

poetry run mypy --strict .
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run black --diff --check .

To build the documentation run:

poetry run sphinx-build docs/source docs/build

License

MIT licensed. See the LICENSE file 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.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

mediawikiapi-1.3-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mediawikiapi-1.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for mediawikiapi-1.3.tar.gz
Algorithm Hash digest
SHA256 452205c2a82585f40e912ba54687affca474abfc6ae5aca16916680cd4a8035a
MD5 2e54148278e8042a63a65ad24398bda7
BLAKE2b-256 6a934c9e14370cdfe80df2bd75548f4f978245066bc5657e4079eb1661367ece

See more details on using hashes here.

File details

Details for the file mediawikiapi-1.3-py3-none-any.whl.

File metadata

  • Download URL: mediawikiapi-1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for mediawikiapi-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 afac9b215390bd33fbc571acad1e9922d79d0b75b1b75c2c06be7c58e790bd79
MD5 ed193b20857770148f8d2cb9e691112c
BLAKE2b-256 f5cb1db12ede27de33eac2436aa26d3547474619f2f519607548340e3648662e

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