{"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":"python","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,"search_vec":"'1.4.0':47 '2014':70 'access':14 'advanc':58 'allow':23 'api':3,72 'articl':29 'current':43 'data':19,34 'design':51 'eas':53 'easi':13 'extract':32 'high':60 'high-volum':59 'imag':39 'inform':73 'librari':6,49 'link':37 'mediawiki':76 'page':41 'pars':17 'provid':12 'python':1,9 'rather':56 'releas':68 'retriev':28,74 'scrape':62,75 'search':26 'seen':66 'sinc':69 'stabl':44 'structur':33 'summari':30 'use':55 'user':24 'version':45 'volum':61 'wikipedia':2,5,21,27,71 'wrapper':10","created_at":"2026-04-14T03:41:47.363164+00:00","updated_at":"2026-04-17T00:40:54.215608+00:00","problems":[{"fix":"Run 'pip install wikipedia' in your terminal to install the library.","cause":"The 'wikipedia' library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'wikipedia'"},{"fix":"Handle the `DisambiguationError` by choosing one of the options provided in the error message or refining your search term.\n```python\nimport wikipedia\ntry:\n    page = wikipedia.page(\"Python\")\nexcept wikipedia.exceptions.DisambiguationError as e:\n    print(f\"Ambiguous term. Options: {e.options}\")\n    # To resolve, pick one, e.g., the first option:\n    # page = wikipedia.page(e.options[0])\n```","cause":"Your search query matched multiple Wikipedia articles, leading to a disambiguation page, and the library cannot automatically choose one.","error":"wikipedia.exceptions.DisambiguationError: \"Your Search Term\" may refer to: ..."},{"fix":"Catch the `PageError` exception and check the spelling of your page title, or use `wikipedia.search()` to find alternative titles.\n```python\nimport wikipedia\ntry:\n    page = wikipedia.page(\"DefinitelyNotARealPageTitle12345\")\nexcept wikipedia.exceptions.PageError:\n    print(\"The requested Wikipedia page does not exist. Please check the title.\")\n    # You might try:\n    # print(wikipedia.search(\"SimilarTerm\"))\n```","cause":"The requested Wikipedia page title does not exist or cannot be found by the library.","error":"wikipedia.exceptions.PageError: \"NonExistentPageName\" does not exist."},{"fix":"Always check if the list returned by `wikipedia.search()` is not empty before attempting to access its elements.\n```python\nimport wikipedia\nresults = wikipedia.search(\"A search term with no results\")\nif results:\n    first_result = results[0]\n    print(f\"First result: {first_result}\")\nelse:\n    print(\"No search results found for the query.\")\n```","cause":"You attempted to access an element from the list returned by `wikipedia.search()`, but the list was empty because no results were found.","error":"IndexError: list index out of range"},{"fix":"Increase the timeout parameter for your requests using `wikipedia.set_timeout()` or check your network connectivity.\n```python\nimport wikipedia\nwikipedia.set_timeout(30) # Increase timeout to 30 seconds (default is 10)\ntry:\n    page = wikipedia.page(\"Long Article Name\")\nexcept wikipedia.exceptions.HTTPTimeoutError:\n    print(\"Request to Wikipedia timed out. Check network or increase timeout.\")\n```","cause":"The request to the Wikipedia API took too long to respond, possibly due to network issues, a slow API, or a very large request.","error":"wikipedia.exceptions.HTTPTimeoutError: Request timed out."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.4.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/goldsmith/Wikipedia","docs":null,"changelog":null,"pypi":"https://pypi.org/project/wikipedia/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}