Wikidata SPARQL Scraper - Query the Knowledge Graph avatar

Wikidata SPARQL Scraper - Query the Knowledge Graph

Pricing

from $0.50 / 1,000 results

Go to Apify Store
Wikidata SPARQL Scraper - Query the Knowledge Graph

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

ninhothedev

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

4 days ago

Last modified

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)
PurposeEntity lookup - fetch known itemsStructured querying - discover unknown items
You give itQIDs, or a keyword searchA SPARQL query (or a preset)
You get backOne row per entity, with its labels, descriptions, aliases, claims and sitelinksOne 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."
FilteringBy entity ID / search termBy any graph pattern: type, property, value, date range, ranking, aggregation
Best forEnriching a list of entities you already haveBuilding 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

FieldTypeDefaultDescription
modeselect: presets / sparqlpresetspresets runs one of the six built-in queries. sparql runs your own query.
presetselectlargest_citiesWhich built-in query to run (only in presets mode).
querystring-Your SPARQL SELECT statement (only in sparql mode).
maxItemsinteger200 (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 ?var automatically 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: astronaut
wdt:P569 ?birth . # date of birth
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?birth
LIMIT 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:Q11303 matches anything that is a skyscraper or a subtype of one. Powerful, but slow - always pair it with a LIMIT inside 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, CONSTRUCT and DESCRIBE do not produce tabular bindings).
  • No PREFIX lines are needed - the endpoint predefines wd:, 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 expensive OPTIONAL blocks, 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:

FieldDescription
query_nameThe preset name, or "custom" for sparql mode
qidsObject mapping each variable that held a Wikidata entity URI to its bare QID/PID
rawThe complete original SPARQL binding, exactly as returned
sourceAlways "wikidata"
scraped_atUTC 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.

Support

Found a bug or need another preset? Open an issue on the actor page.