Skip to main content

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

Metadata

Release files for mediawikiapi 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mediawikiapi 1.3
File Size Uploaded
mediawikiapi-1.3.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mediawikiapi 1.3
File Interpreter ABI Platform
mediawikiapi-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.8 kB

Release files / mediawikiapi-1.3.tar.gz

Download URL mediawikiapi-1.3.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
452205c2a82585f40e912ba54687affca474abfc6ae5aca16916680cd4a8035a
BLAKE2b-256 checksum
How to use checksums
6a934c9e14370cdfe80df2bd75548f4f978245066bc5657e4079eb1661367ece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.13.2 Linux/6.8.0-1021-azure

Release files / mediawikiapi-1.3-py3-none-any.whl

Download URL mediawikiapi-1.3-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afac9b215390bd33fbc571acad1e9922d79d0b75b1b75c2c06be7c58e790bd79
BLAKE2b-256 checksum
How to use checksums
f5cb1db12ede27de33eac2436aa26d3547474619f2f519607548340e3648662e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.13.2 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

1.3 This release

2 release files

1.2

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.3

1 release file

1.1.0

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page