Registry / http-networking / wikipedia-api

wikipedia-api

JSON →
library0.15.0pypypi✓ verified 26d ago

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-api
INSTALL
IMPORT
SIG · WIKIPEDIA-API
W
wikipedia-api
http-networkingpythonv0.15.0
Install
2.7s avg
Import
373ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.15.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.308s · 24.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.288s · 25MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Wikipedia
from wikipediaapi import Wikipedia
For the synchronous client.
AsyncWikipedia
from wikipediaapi import AsyncWikipedia
For the asynchronous client.

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.

import wikipediaapi import os # It's crucial to provide a User-Agent that identifies your project. # Replace 'MyProjectName (contact@example.com)' with your actual project name and contact info. # See https://meta.wikimedia.org/wiki/User-Agent_policy wiki_wiki = wikipediaapi.Wikipedia( user_agent=os.environ.get('WIKIPEDIA_USER_AGENT', 'MyPythonApp/1.0 (contact@example.com)'), language='en' ) page_py = wiki_wiki.page('Python (programming language)') if page_py.exists(): print(f"Page title: {page_py.title}") print(f"Summary: {page_py.summary[0:200]}...") print(f"Full URL: {page_py.fullurl}") # Example of accessing sections for s in page_py.sections: print(f"Section: {s.title}") break # Just print the first section title for brevity else: print(f"Page 'Python (programming language)' does not exist.")
Debug
Known issues
breakingThe `user_agent` parameter became mandatory in the `Wikipedia` and `AsyncWikipedia` constructors starting from version 0.6.0. Failing to provide it will raise an error.
fix
Always pass a descriptive `user_agent` string as the first argument to the constructor, e.g., `wikipediaapi.Wikipedia(user_agent='MyProjectName (contact@example.com)', ...)`.
affects: >=0.6.0
breakingThe position of the `variant` parameter in the `Wikipedia` and `AsyncWikipedia` constructors changed to the third argument in versions 0.7.x. If you were explicitly passing `variant` by position in older versions, this will break.
fix
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.
affects: >=0.7.0
gotchaWhen using the `AsyncWikipedia` client, all data-fetching attributes (e.g., `summary`, `text`, `sections`, `links`, `fullurl`, `pageid`) are coroutines and must be `awaited`. Failing to do so will result in a coroutine object instead of the expected data.
fix
Prepend `await` to calls for data-fetching attributes, e.g., `await page.summary` instead of `page.summary`.
affects: All versions with `AsyncWikipedia`
gotchaProviding an inappropriate or missing `User-Agent` string can lead to your requests being blocked by Wikimedia servers. It's essential to follow Wikimedia's User-Agent policy, including providing a project name and contact information.
fix
Use a descriptive `user_agent` like `'MyProjectName/1.0 (https://myproject.com; contact@example.com)'` or `'MyProjectName (contact@example.com)'`.
affects: All versions
gotchaExcessive or rapid requests to the Wikipedia API, especially without proper delays, can lead to your IP being temporarily or permanently blocked by Wikimedia's servers due to rate limiting.
fix
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.
affects: All versions
breaking`wikipediaapi` versions 0.8.0 and newer utilize Python 3.10+ type hint syntax (e.g., `X | Y` for union types). Running these versions on Python environments older than 3.10 will result in a `TypeError: unsupported operand type(s) for |: 'type' and 'type'` during import.
fix
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.
affects: >=0.8.0 (when running on Python < 3.10)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'wikipedia_api'
The Python module name to import is `wikipediaapi` (without hyphen or underscore), even though the installation package name is `wikipedia-api`.
fix
import wikipediaapi
AttributeError: 'WikipediaPage' object has no attribute 'content'
The `wikipedia-api` library uses the attribute `text` to access the main textual content of a Wikipedia page, not `content`.
fix
page_object.text
AttributeError: 'WikipediaPage' object has no attribute 'info'
The `WikipediaPage` object in `wikipedia-api` does not have a direct `info` attribute; detailed information is accessed via other attributes like `sections`, `links`, or `categories`.
fix
Use `page_object.sections`, `page_object.links`, `page_object.categories`, or `page_object.summary` to access specific information.
TypeError: 'builtin_function_or_method' object is not subscriptable
You are attempting to access properties of a `WikipediaPage` object using dictionary-style bracket notation (e.g., `page['sections']`) instead of dot notation.
fix
Use dot notation, such as `page.sections` (or `page.links`, `page.categories`, etc.), to access properties of the `WikipediaPage` object.
Upgrade
Version history
0.15.0latest on PyPI · released May 26, 2026
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Wikipedia API.
clickoptionalUsed for command-line interface (CLI) functionality.
Agent activity
37 hits · last 30 days
node
30
OpenAI (training)
1
Resources