Wikidata SPARQL Scraper - Query the Knowledge Graph
Pricing
from $0.50 / 1,000 results
Wikidata SPARQL Scraper - Query the Knowledge Graph
$0.5/1K š„ Wikidata SPARQL scraper! Query the world knowledge graph ā cities, laureates, UNESCO sites & custom queries. No key. JSON, CSV, Excel or API in seconds. Power research & RAG ā”
Pricing
from $0.50 / 1,000 results
Rating
0.0
(0)
Developer
ninhothedev
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
4 days ago
Last modified
Categories
Share
Wikidata SPARQL Scraper - Query the World Knowledge Graph (No API Key)
Run any SPARQL query against Wikidata, the free structured knowledge graph behind Wikipedia, and get back clean, flat, tabular rows. Every SPARQL variable becomes its own column, entity URIs are resolved to bare QIDs, and coordinates are split into latitude/longitude - ready for CSV, Excel, pandas, a vector store, or a database.
Six hand-tuned preset queries ship with the actor, so you can pull useful datasets (largest cities, Nobel laureates, UNESCO World Heritage sites, tallest buildings, GDP by country, programming languages) without writing a single line of SPARQL.
No API key. No login. No proxy required. Wikidata's Query Service is free and open.
How is this different from the Wikidata Scraper?
This actor is the query counterpart to ninhothedev/wikidata-scraper.
Wikidata Scraper (wikidata-scraper) | Wikidata SPARQL Scraper (this actor) | |
|---|---|---|
| Purpose | Entity lookup - fetch known items | Structured querying - discover unknown items |
| You give it | QIDs, or a keyword search | A SPARQL query (or a preset) |
| You get back | One row per entity, with its labels, descriptions, aliases, claims and sitelinks | One row per query result binding, with one column per SPARQL variable |
| Typical question | "What does Wikidata know about Q42?" | "Give me every city over 10M people with its coordinates." |
| Filtering | By entity ID / search term | By any graph pattern: type, property, value, date range, ranking, aggregation |
| Best for | Enriching a list of entities you already have | Building a dataset from scratch out of the knowledge graph |
Rule of thumb: if you already know which things you want, use wikidata-scraper. If you want the graph to find the things for you (by type, property, ranking or relationship), use this one.
What you can do with it
- Build research datasets - every UNESCO site with coordinates, every Nobel laureate by decade, every country's GDP over time. Reproducible and citable, straight from the source.
- Enrich RAG / LLM pipelines - pull authoritative structured facts (dates, coordinates, identifiers, relationships) to ground a model and cut hallucinations. Each row keeps its QID so you can link back to canonical entities.
- Knowledge graph work - export subgraphs, map external identifiers (ISO codes, VIAF, GND, IMDb, ORCID) to QIDs, or seed your own graph database.
- Data journalism - answer questions like "which heads of state studied abroad" or "how have skyscraper heights grown per decade" with a single query, and get a spreadsheet back.
- Entity resolution & reference data - generate clean lookup tables of countries, languages, currencies, professions, chemical compounds, species, or anything else Wikidata models.
Input
| Field | Type | Default | Description |
|---|---|---|---|
mode | select: presets / sparql | presets | presets runs one of the six built-in queries. sparql runs your own query. |
preset | select | largest_cities | Which built-in query to run (only in presets mode). |
query | string | - | Your SPARQL SELECT statement (only in sparql mode). |
maxItems | integer | 200 (max 2000) | Maximum result rows. Also injected as the LIMIT for presets and for custom queries that have none. |
Example - run a preset
{"mode": "presets","preset": "largest_cities","maxItems": 500}
Example - run your own SPARQL
{"mode": "sparql","query": "SELECT ?country ?countryLabel ?capital ?capitalLabel ?coord WHERE { ?country wdt:P31 wd:Q6256 ; wdt:P36 ?capital . OPTIONAL { ?capital wdt:P625 ?coord . } SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } } ORDER BY ?countryLabel","maxItems": 200}
The six built-in presets
Every preset is tuned to return fast (well inside Wikidata's 60-second limit) and to include labels, identifiers and coordinates where they exist.
1. largest_cities
The most populous cities on earth, ranked by population.
Columns: city, cityLabel, cityDescription, population, country, countryLabel, coord, coord_lat, coord_lon
Use for: geo datasets, market sizing, map visualisations, city reference tables.
2. nobel_laureates
Nobel Prize winners across all categories, newest first.
Columns: laureate, laureateLabel, laureateDescription, award, awardLabel (the prize category), year, countryLabel (citizenship)
Use for: science history analysis, prize-by-country studies, biography enrichment.
3. unesco_sites
UNESCO World Heritage sites worldwide.
Columns: site, siteLabel, siteDescription, country, countryLabel, coord, coord_lat, coord_lon, inscribed (year added to the list)
Use for: travel and tourism products, cultural heritage research, map layers.
4. tallest_buildings
Completed buildings ranked by height in metres (unbuilt proposals and obvious data-entry outliers are filtered out by requiring an opening date and a plausible 150-1200 m height).
Columns: building, buildingLabel, height, opened, city, cityLabel, country, countryLabel, coord, coord_lat, coord_lon
Use for: architecture datasets, construction trend analysis, city skylines.
5. countries_gdp
Sovereign states ranked by nominal GDP.
Columns: country, countryLabel, iso (ISO 3166-1 alpha-3), gdp, gdpDate (the year the figure refers to), population, capitalLabel
Use for: economic dashboards, country reference tables, ISO-code mapping.
6. programming_languages
Programming languages ordered by inception date - the history of computing in one table.
Columns: lang, langLabel, langDescription, inception, creator, creatorLabel, paradigmLabel, influencedByLabel
Use for: tech history, developer content, language family trees.
Writing your own SPARQL
Wikidata SPARQL is easier than it looks. Three building blocks cover most queries:
wd:Qā¦- an entity (a thing).wd:Q515= city,wd:Q6256= country,wd:Q5= human.wdt:Pā¦- a property (a relationship).wdt:P31= instance of,wdt:P17= country,wdt:P1082= population,wdt:P625= coordinates,wdt:P569= date of birth.- The label service - add this line and every
?varautomatically gains a readable?varLabel(and?varDescription):
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
A minimal query - all humans who are astronauts, with their birth dates:
SELECT ?person ?personLabel ?birth WHERE {?person wdt:P106 wd:Q11631 ; # occupation: astronautwdt:P569 ?birth . # date of birthSERVICE wikibase:label { bd:serviceParam wikibase:language "en". }}ORDER BY ?birthLIMIT 200
Useful patterns:
- Optional data: wrap properties that not every item has in
OPTIONAL { ⦠}so rows are not dropped. - Subclasses:
?x wdt:P31/wdt:P279* wd:Q11303matches anything that is a skyscraper or a subtype of one. Powerful, but slow - always pair it with aLIMITinside a subquery. - Qualifiers: use
p:/ps:/pq:to reach statement-level data, e.g. the year attached to an award:?p p:P166 ?st . ?st ps:P166 ?award ; pq:P585 ?date . - Ranking:
ORDER BY DESC(?population) LIMIT 100. - Aggregation:
SELECT ?countryLabel (COUNT(?city) AS ?cities) ⦠GROUP BY ?countryLabel.
Tips and limits:
- Only SELECT queries are supported (
ASK,CONSTRUCTandDESCRIBEdo not produce tabular bindings). - No
PREFIXlines are needed - the endpoint predefineswd:,wdt:,p:,ps:,pq:,wikibase:,rdfs:and friends. - Wikidata enforces a hard 60-second timeout. If you hit it the actor tells you so; add a
LIMIT, drop expensiveOPTIONALblocks, or narrow the property path. - Prototype interactively at query.wikidata.org - it has autocomplete and a query-example gallery - then paste the working query in here.
Output
One dataset item per SPARQL result binding. Because the columns depend on your query, the flattened variables are merged into the top level of the row and the untouched binding is preserved under raw.
Fixed fields on every row:
| Field | Description |
|---|---|
query_name | The preset name, or "custom" for sparql mode |
qids | Object mapping each variable that held a Wikidata entity URI to its bare QID/PID |
raw | The complete original SPARQL binding, exactly as returned |
source | Always "wikidata" |
scraped_at | UTC ISO-8601 timestamp of the run |
Plus one column per SPARQL variable, flattened from the SPARQL-JSON {"type": ā¦, "value": ā¦} cell to a plain value (numeric datatypes become numbers, booleans become booleans). Coordinate values additionally produce <var>_lat and <var>_lon. All fields are nullable - unbound optional variables appear as null.
Real sample row (largest_cities):
{"query_name": "largest_cities","city": "http://www.wikidata.org/entity/Q956","cityLabel": "Beijing","population": 21893095,"country": "http://www.wikidata.org/entity/Q148","countryLabel": "People's Republic of China","coord": "Point(116.407526 39.90403)","coord_lat": 39.90403,"coord_lon": 116.407526,"qids": { "city": "Q956", "country": "Q148" },"raw": { "city": { "type": "uri", "value": "http://www.wikidata.org/entity/Q956" }, "...": "..." },"source": "wikidata","scraped_at": "2026-07-28T13:41:07.512834+00:00"}
Export as JSON, CSV, Excel, XML or HTML from the Apify UI or API.
Pricing
Roughly $0.50 per 1,000 result rows on Apify's pay-per-event style compute. The actor runs on 512 MB and a single query returning 2,000 rows finishes in seconds, so most runs cost a fraction of a cent.
Notes on fair use
The Wikidata Query Service is a free public service run by the Wikimedia Foundation. This actor sends a descriptive User-Agent (required - anonymous requests get HTTP 403), retries transient gateway errors with backoff, and issues exactly one query per run. Keep maxItems reasonable and avoid hammering the endpoint with heavy queries. Wikidata content is published under CC0 - free for any use, attribution appreciated.
Related actors
- Wikidata Scraper - entity lookup by QID or search term
- Wikipedia Scraper - article text, summaries and metadata
- OpenAlex Scraper - open scholarly works, authors and institutions
- GLEIF Scraper - global LEI legal-entity reference data
Support
Found a bug or need another preset? Open an issue on the actor page.