Wikipedia-API is a Python wrapper that provides an easy-to-use interface for interacting with Wikipedia's MediaWiki API. It supports extracting various types of information, including text, sections, links, categories, and translations from Wikipedia pages. The library offers both synchronous and asynchronous clients for flexible integration, and is actively maintained with frequent releases, currently at version 0.13.0.
pip install wikipedia-apiVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the synchronous Wikipedia client, retrieve a page by title, check its existence, and access its summary, URL, and sections. A descriptive user_agent is mandatory.
Always pass a descriptive `user_agent` string as the first argument to the constructor, e.g., `wikipediaapi.Wikipedia(user_agent='MyProjectName (contact@example.com)', ...)`.
Ensure `variant` is passed as a keyword argument (e.g., `wikipediaapi.Wikipedia(..., language='en', variant='zh-tw')`) or as the third positional argument if maintaining positional arguments.
Prepend `await` to calls for data-fetching attributes, e.g., `await page.summary` instead of `page.summary`.
Use a descriptive `user_agent` like `'MyProjectName/1.0 (https://myproject.com; contact@example.com)'` or `'MyProjectName (contact@example.com)'`.
Implement rate limiting or introduce delays between requests, particularly for automated scraping or high-volume data retrieval. Consider using `time.sleep()` between calls if performing many requests.
Upgrade your Python environment to 3.10 or newer. Alternatively, if you must use an older Python version (e.g., 3.9), downgrade `wikipediaapi` to a version prior to 0.8.0.
import wikipediaapi
page_object.text
Use `page_object.sections`, `page_object.links`, `page_object.categories`, or `page_object.summary` to access specific information.
Use dot notation, such as `page.sections` (or `page.links`, `page.categories`, etc.), to access properties of the `WikipediaPage` object.