Wikidata API
www.wikidata.org · Data
Structured knowledge graph — 100M+ machine-readable facts about people, places, events, and things. Query with SPARQL or REST. Powers Siri, Alexa, and Google Knowledge Graph. Free.
Authentication
No authentication requiredFree to use with no key needed.
Sample Requests
GET
Search entities
Search Wikidata for entities matching a name.
https://www.wikidata.org/w/api.php?limit=3&action=wbsearchentities&format=json&search=Marie Curie&language=en
Hover any highlighted part to learn what it does
curl -X GET "https://www.wikidata.org/w/api.php?limit=3&action=wbsearchentities&format=json&search=Marie%20Curie&language=en"
import requests
params = {
"limit": "3",
"action": "wbsearchentities",
"format": "json",
"search": "Marie Curie",
"language": "en"
}
response = requests.get(
"https://www.wikidata.org/w/api.php",
params=params,
)
print(response.json())const url = new URL('https://www.wikidata.org/w/api.php');
url.searchParams.set('limit', '3');
url.searchParams.set('action', 'wbsearchentities');
url.searchParams.set('format', 'json');
url.searchParams.set('search', 'Marie Curie');
url.searchParams.set('language', 'en');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://www.wikidata.org/w/api.php")
q := baseURL.Query()
q.Set("limit", "3")
q.Set("action", "wbsearchentities")
q.Set("format", "json")
q.Set("search", "Marie Curie")
q.Set("language", "en")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://www.wikidata.org/w/api.php")
uri.query = URI.encode_www_form({
"limit" => "3",
"action" => "wbsearchentities",
"format" => "json",
"search" => "Marie Curie",
"language" => "en"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://www.wikidata.org/w/api.php?" . http_build_query([
"limit" => "3",
"action" => "wbsearchentities",
"format" => "json",
"search" => "Marie Curie",
"language" => "en"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
SPARQL query
Find people born in New York City using SPARQL.
https://www.wikidata.org/w/api.phphttps:/query.wikidata.org/sparql?query=SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5&format=json
Hover any highlighted part to learn what it does
curl -X GET "https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%20%3Fitem%20wdt%3AP31%20wd%3AQ5%20%3B%20wdt%3AP19%20wd%3AQ60%20.%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%20%7D%20LIMIT%205&format=json"
import requests
params = {
"query": "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5",
"format": "json"
}
response = requests.get(
"https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql",
params=params,
)
print(response.json())const url = new URL('https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql');
url.searchParams.set('query', 'SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5');
url.searchParams.set('format', 'json');
const response = await fetch(url);
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql")
q := baseURL.Query()
q.Set("query", "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5")
q.Set("format", "json")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql")
uri.query = URI.encode_www_form({
"query" => "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5",
"format" => "json"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://www.wikidata.org/w/api.phphttps://query.wikidata.org/sparql?" . http_build_query([
"query" => "SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 ; wdt:P19 wd:Q60 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 5",
"format" => "json"
]);
$opts = ["http" => [
"method" => "GET",
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- No API key needed
- Search: GET https://www.wikidata.org/w/api.php?action=wbsearchentities&search=Einstein&language=en&format=json
- Get item: GET https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q937&format=json (Q937=Einstein)
- SPARQL: POST https://query.wikidata.org/sparql with query param
- Use Wikidata Query Service UI at query.wikidata.org to build queries