wikidata-dl is a command line program for downloading data from Wikidata based on SPARQL queries.
pip install wikidata_dl
Download all results returned by the query and store them in the wikidata
directory in the current working directory:
wikidata-dl /path/to/my-query.sparql
Show only the result count returned by the query without downloading anything:
wikidata-dl --dry-run /path/to/my-query.sparql
For a complete reference of the command line options run:
wikidata-dl --help
The following query returns IDs for all Wikidata entities that are an instance of (P31) a continent (Q5107).
SELECT ?item WHERE {
?item wdt:P31 wd:Q5107.
}
- The SPARQL query you pass to the program must return Wikibase IDs.
- The query variable where the entity ID is stored must be called
item
.