goldsmith/Wikipedia 1.5: a small MediaWiki wrapper that now raises on ambiguous titles
A Pythonic wrapper for the Wikipedia API
At a glance
- What is it?
- The wikipedia package gives Python scripts search, summaries, page content, links and images from Wikipedia in a few calls. Version 1.5 tightened title resolution and error handling, and its own documentation sends heavy scraping elsewhere.
- Who is it for?
- Use this package for scripts, notebooks and small tools that need a summary, a page's links or a language switch from Wikipedia, and set a user agent before the first call. Pick Pywikibot or another MediaWiki client if you need bulk requests, a larger API or a bot account.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 31 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- goldsmith/Wikipedia3,015 ★ · +10
| Repository | 2026-10-08 | 2026-11-24 |
|---|---|---|
| goldsmith/Wikipedia | 3k | 3k |
10 Stars in the last 47 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Four calls cover search, summary, page object and language switch
The whole surface is visible in a short session. `wikipedia.summary("Wikipedia", sentences=1)` returns a trimmed summary string. `wikipedia.search("Barack")` returns a list of titles, including `'Barack (disambiguation)'`. `wikipedia.page("New York City")` returns a page object with `title`, `url`, `content` and `links`, and `ny.links[0]` gives `'116 John Street'`.
Switching language is a single call. After `wikipedia.set_lang("fr")`, a summary of Facebook comes back from the French edition. The library wraps the MediaWiki API, so each of these calls turns into an HTTP request against the wiki you selected.
There is no query language here and no way to build a custom MediaWiki request through the documented interface. What you get is the set of helpers above plus the setters for user agent, timeout and rate limiting.
Installing wikipedia 1.5 means leaving Python 3.9 and older behind
PyPI currently serves Wikipedia 1.4.0. For the 1.5.0 behavior covered here, install the upstream source at the pinned commit with Git and Python 3.10 or newer.
pip install "wikipedia @ git+https://github.com/goldsmith/Wikipedia.git@d867847cbfdba66ff41d593b9af0be3d9a5b994c"The 1.5.0 source declares `requires-python = ">=3.10"` and lists Python 3.10 through 3.14 in its classifiers. For the earlier package on PyPI, use `pip install "wikipedia<1.5"`.
Two runtime dependencies are pinned in `requirements.txt`: `beautifulsoup4>=4.12.3,<5` and `requests>=2.32.4,<3`. Both have upper bounds on the major version, so a project that already pins `requests` 3 would conflict. The build backend requires `setuptools>=77`, which only matters if you build from source.
Wikimedia asks for a user agent and the library will not set a meaningful one for you
Wikimedia asks that API clients identify themselves, and the project asks you to call `set_user_agent` with a contact address:
>>> wikipedia.set_user_agent("my-cool-project/1.0 (https://example.com/contact)")The string should name your own project and a way to reach you. A script that skips this step still runs, but it presents no identity to the wiki operators, and it is the one piece of etiquette the library cannot do on your behalf.
The rest is handled internally. Requests go over HTTPS and share a connection pool. The timeouts are 5 seconds to connect and 15 seconds to read, and `set_timeout` changes them. Transient failures are retried at most twice before the library raises `RequestError` or `HTTPTimeoutError`, so your code needs an `except` for those two names.
Rate limiting is opt-in and the cache lasts five minutes
`set_rate_limiting(True)` enforces at least 50 ms between requests. It is off by default, so a loop over a thousand titles will fire as fast as the connection allows unless you turn it on. For anything that loops, turn it on first.
Results are cached for five minutes, so asking for the same page twice in that window does not send a second request. The practical effect is on tests and notebooks: re-running a cell gives you the earlier answer for five minutes, and an edit made to the live article in that window will not show up.
The documentation gives no setting to change the cache lifetime or to turn it off. If you need fresh content on every call, this library does not offer a documented way to get it.
Version 1.5 raises on disambiguation pages instead of picking an article
The 1.5 notes summarise thirteen years of fixes. Exact titles now resolve before suggestions. Disambiguation pages raise, where before the library silently picked a different article. Redirects and sections behave, missing properties return `[]` or `None` instead of throwing, and page objects remember which language they were fetched in.
The disambiguation change is the one that can break existing code. A script that called `wikipedia.page("Barack")` and received some article will now get an exception, and the fix is to catch it or to pass a more specific title from `wikipedia.search`. The list of changes is in `CHANGELOG.md`, and the people whose pull requests informed the release are named in `CONTRIBUTIONS.md`.
The tests were rebuilt as an offline suite that stubs HTTP, so running them does not touch Wikipedia.
The package is built for ease of use and points serious scraping to Pywikibot
The project is direct about its ceiling. It was designed for ease of use and simplicity, not for advanced use. If you plan serious scraping or automated requests, the project asks you to use Pywikibot or one of the other Python MediaWiki wrappers, because those have a larger API and rate limiting built in.
That sets the boundary for choosing it. A cron job that fetches a few hundred summaries a day is within what the 50 ms limiter and five-minute cache were built for. A crawler that walks the link graph of an entire category belongs elsewhere.
The repository is marked Beta in its classifiers, and the homepage points to wikipedia.readthedocs.org, with the Quickstart and Full API pages linked from the project's documentation section.
Running the tests and the live smoke check without hammering the API
Contributors clone the repository and run:
$ pip install -e '.[dev]'
$ bash runtestsThe `dev` extra pulls in pytest, pytest-cov, build, twine and ruff. The suite runs offline because it stubs HTTP. `python scripts/live_smoke.py` runs opt-in checks against the real API, rate limited and capped at 30 requests.
To build the documentation, install the `docs` extra with `pip install -e '.[docs]'` and run `sphinx -b html docs/source docs/_build/html`. The ruff configuration in `pyproject.toml` selects only a few error classes (`E9`, `F63`, `F7`, `F82`), so it catches syntax and undefined-name problems and does not enforce a style.
Editorial conclusion
Use this package for scripts, notebooks and small tools that need a summary, a page's links or a language switch from Wikipedia, and set a user agent before the first call. Pick Pywikibot or another MediaWiki client if you need bulk requests, a larger API or a bot account. Before upgrading an older project, check every call that relied on a disambiguation page silently returning some article, because 1.5 raises instead.
Frequently asked questions
How do I use the Wikipedia API in Python with goldsmith/Wikipedia?
Install the 1.5.0 source using the pinned command in the installation section. Then call `wikipedia.search`, `wikipedia.summary` or `wikipedia.page` to query the MediaWiki API.
How do I use Wikipedia in Python?
Import wikipedia and call wikipedia.summary("Wikipedia", sentences=1) for a short summary, or wikipedia.page("New York City") for a page object with title, url, content and links. Version 1.5 needs Python 3.10 or newer.
How do I use the Wikipedia API without overloading it?
Call set_user_agent with your project name and contact, and turn on set_rate_limiting(True) to keep at least 50 ms between requests. Results are also cached for five minutes. For serious scraping the project recommends Pywikibot.
Official sources
Was this useful?