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 and Python 2.7.

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 .

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.2.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

mediawikiapi-1.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mediawikiapi-1.2.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for mediawikiapi-1.2.tar.gz
Algorithm Hash digest
SHA256 1ef5586c631c8731da4249b73728c2d7709f88dec0aa4281af57f570104fdfd0
MD5 930097b6320e9ea7329aafbbd4dfd40e
BLAKE2b-256 038280a16370dfa9bb9fe11a29820c5b9d4c6dae4c28c4613a2226c09a29f1f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mediawikiapi-1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for mediawikiapi-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 73e9355e8185098aae8efe77f9d545e8c338f7be6314537b790c7a51a0e31df6
MD5 248cc94782fbc714f9790d1a5550dd82
BLAKE2b-256 2e5f0cb0c7de6cdf8f32b0fdfeebc5a892bd76506ea5a420129d9c0aa696945c

See more details on using hashes here.

Supported by

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