Querying Wikidata in Python: Avoiding Duplicate Rows in City Population Data
A developer explains how to query the Wikidata SPARQL endpoint from Python using a plain GET request with JSON output and a descriptive User-Agent, since the default one is blocked with a 403. The article notes that population values and reverse country lookups can produce duplicate rows, which is the main data-quality pitfall. It provides a helper function that handles HTTP 429 throttling by honoring the Retry-After header. A worked example covers six major cities, showing their populations and countries from a December 2026 run. The author also outlines the service's limits, including a 60-second query deadline and a rate of 30 error queries per minute.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in