Wikipedia API
Query Wikipedia article content, summaries and search via the MediaWiki API.
What it does
Wikipedia is queryable through the MediaWiki Action API (search, page content, links, categories, revisions) and a REST API (clean page summaries, HTML, related pages, on-this-day). Between them you can search articles, pull an intro extract, get the lead image, or fetch full wikitext/HTML.
Base URL
Authentication
None for reads, but a descriptive User-Agent (app name + contact) is required by policy. The clean-summary REST endpoint is https://en.wikipedia.org/api/rest_v1/page/summary/{title}. Swap en for other language editions.
Code examples
curl -s "https://en.wikipedia.org/api/rest_v1/page/summary/Alan_Turing" \ -H "User-Agent: larzos-demo/1.0 (contact@example.com)"
import requests
H = {"User-Agent": "larzos-demo/1.0 (contact@example.com)"}
r = requests.get("https://en.wikipedia.org/w/api.php", params={
"action": "query", "format": "json", "prop": "extracts",
"exintro": 1, "explaintext": 1, "titles": "Photosynthesis"},
headers=H, timeout=10)
page = next(iter(r.json()["query"]["pages"].values()))
print(page["extract"][:300])Rate limits & quotas
No key, but heavy use should be authenticated (an OAuth token raises your limit) and you should stay well under ~200 requests/second in aggregate, batch titles (up to 50), and honour maxlag. The REST API is cached and CORS-enabled — prefer it for simple summary/extract needs.
Key response fields
| (REST summary) title / extract / description | Title, plain-text intro, short descriptor |
| (REST summary) thumbnail.source / content_urls.desktop.page | Lead image and canonical URL |
| (Action) query.pages[].extract | Intro or full plain-text (with exintro/explaintext) |
| (Action) query.search[] | Search results with title and snippet |
| (Action) continue | Token to fetch the next batch |
Common errors
| 403 | Missing or generic User-Agent — set a real one with contact info. |
| (REST) 404 | No page with that exact title — run a search first, or follow a redirect. |
| (Action) 'missing' page | The page id is -1 with a missing flag — not an HTTP error. |
| 429 / maxlag | Back off — respect Retry-After and the maxlag parameter. |
When to use it (and alternatives)
The default for encyclopaedic text: article summaries, ‘learn more’ panels, disambiguation, on-this-day features. For structured facts (population, birth date, coordinates as data) use Wikidata instead of parsing prose.
FAQ
Action API or REST API?
Use the REST page/summary endpoint for a clean intro + image + URL in one cached call. Use the Action API when you need search, categories, links, full wikitext, revisions or fine control.
How do I get the intro paragraph only?
Action API: prop=extracts&exintro=1&explaintext=1. Or just use the REST summary endpoint, whose extract is the intro by design.
Why am I blocked?
Almost always a missing or generic User-Agent. Wikimedia’s policy requires one identifying your tool and a way to contact you.
New to APIs?
Short guides for working with this API — and any other.