{"id":5742,"library":"wikipedia","title":"Python Wikipedia API","description":"The `wikipedia` library is a Pythonic wrapper that provides easy access to and parsing of data from Wikipedia. It allows users to search Wikipedia, retrieve article summaries, and extract structured data such as links and images from pages. The current stable version is 1.4.0. This library is designed for ease of use rather than advanced, high-volume scraping, and has not seen a release since 2014.","status":"maintenance","version":"1.4.0","language":"en","source_language":"en","source_url":"https://github.com/goldsmith/Wikipedia","tags":["wikipedia","api","information retrieval","scraping","mediawiki"],"install":[{"cmd":"pip install wikipedia","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary module for interacting with the Wikipedia API.","symbol":"wikipedia","correct":"import wikipedia"},{"note":"Required for handling cases where a search query matches multiple Wikipedia pages.","symbol":"DisambiguationError","correct":"from wikipedia.exceptions import DisambiguationError"},{"note":"Required for handling cases where a search query does not match any Wikipedia pages.","symbol":"PageError","correct":"from wikipedia.exceptions import PageError"}],"quickstart":{"code":"import wikipedia\n\n# Set language (optional, default is 'en')\nwikipedia.set_lang(\"en\")\n\n# Search for pages\nsearch_results = wikipedia.search(\"Artificial Intelligence\")\nprint(f\"Search results: {search_results[:3]}...\")\n\n# Get a summary of a page\ntry:\n    summary_text = wikipedia.summary(\"Artificial intelligence\", sentences=2)\n    print(f\"Summary: {summary_text}\")\nexcept wikipedia.exceptions.DisambiguationError as e:\n    print(f\"Disambiguation options: {e.options}\")\n    # Example of handling by picking the first option\n    # print(f\"Picking first option: {wikipedia.summary(e.options[0], sentences=2)}\")\nexcept wikipedia.exceptions.PageError:\n    print(\"Page not found.\")\n\n# Get a full page object\ntry:\n    page = wikipedia.page(\"Artificial intelligence\")\n    print(f\"Page title: {page.title}\")\n    print(f\"Page URL: {page.url}\")\n    # Access content, links, etc.\n    # print(f\"Page content (first 200 chars): {page.content[:200]}...\")\n    # print(f\"Page links (first 5): {page.links[:5]}\")\nexcept wikipedia.exceptions.PageError:\n    print(\"Page not found for full object.\")\nexcept wikipedia.exceptions.DisambiguationError as e:\n    print(f\"Disambiguation options for page: {e.options}\")\n","lang":"python","description":"This quickstart demonstrates how to search for Wikipedia pages, retrieve a concise summary, and access a full page object including its title and URL. It also includes basic error handling for common `DisambiguationError` and `PageError` exceptions."},"warnings":[{"fix":"Always wrap calls to `summary()` and `page()` in a `try-except` block to catch `DisambiguationError` and either present options to the user or programmatically select one from `e.options`.","message":"Calling `wikipedia.summary()` or `wikipedia.page()` with an ambiguous query (e.g., 'Mercury') will raise a `wikipedia.exceptions.DisambiguationError`.","severity":"gotcha","affected_versions":"1.x.x"},{"fix":"Catch `wikipedia.exceptions.PageError` in your `try-except` blocks and handle cases where no matching page is found, e.g., by suggesting alternative queries.","message":"If a query does not match any Wikipedia page, `wikipedia.summary()` or `wikipedia.page()` will raise a `wikipedia.exceptions.PageError`.","severity":"gotcha","affected_versions":"1.x.x"},{"fix":"For precise queries, consider setting `auto_suggest=False` in `wikipedia.page()` and `wikipedia.summary()` calls, and handle `PageError` explicitly if the exact page isn't found.","message":"The library's default `auto_suggest=True` behavior can sometimes silently correct a query to an unintended or incorrect page, leading to unexpected results or `PageError` for what seems like a valid query. For example, 'Commander Worf' might become 'commander wharf'.","severity":"gotcha","affected_versions":"1.x.x"},{"fix":"For new projects or if encountering issues, consider evaluating alternative, more actively maintained Python wrappers for the Wikipedia API, such as `wikipedia-api` (martin-majlis/Wikipedia-API).","message":"This `wikipedia` library (goldsmith/Wikipedia) has not been updated since November 2014 (version 1.4.0). While still functional, it may not support the latest Wikipedia API features, might have unaddressed bugs, or could eventually break due to API changes.","severity":"deprecated","affected_versions":"1.4.0"},{"fix":"For serious scraping, automated requests, or editing, use more advanced MediaWiki API wrappers like Pywikibot, which offer rate limiting and other features for considerate interaction with Wikimedia infrastructure.","message":"This library is designed for simple, casual use. It does not include features like rate limiting, robust error handling for network issues, or extensive scraping capabilities. Using it for high-volume or aggressive scraping can lead to IP blocking or violations of Wikimedia's terms of service.","severity":"gotcha","affected_versions":"1.x.x"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}