NAME

wdq - command line access to Wikidata Query Service

USAGE

Access Wikidata Query Service via command line. In query mode (default), a SPARQL query is read from STDIN or option --query. Default namespaces are and SELECT clause are added if missing. In lookup mode, Wikidata entity ids, URLs, or Wikimedia project URLs are read from STDIN to look up label and description.

EXAMPLES

# get all parts of the solar system
wdq -q '?c wdt:P361 wd:Q544' 
wdq -q '{ ?c wdt:P361 wd:Q544 }'                # equivalent
wdq -q 'SELECT * WHERE { ?c wdt:P361 wd:Q544 }' # equivalent

# look up label and description 
echo Q1 | wdq lookup

OPTIONS

--query|-q QUERY

Query or query file (- for STDIN as default)

--format|-f FORMAT

Output format. Supported formats include json, xml, tsv, and csv SPARQL result format, simple for flat JSON without language tags (default), and ldjson for line delimited flat json. For more flexible output options pipe to another tool such as jq, miller, and catmandu. If Catmandu is installed, its exporters can directly be used with option export.

--limit INTEGER

Add or override a LIMIT clause to limitate the number of results. Single-digit options such as -1 can also be used to also set a limit.

--export EXPORTER

Use a Catmandu exporter as output format, for instance XLS (Excel) and Markdown tables (Table). The following produce same output:

wdq --export Foo 
wdq --format ldjson | catmandu convert to Foo

Use Catmandu config file (catmandu.yml) to further configure export.

--ids|-i

Return Wikidata identifiers as strings instead of URIs (except for output format xml and json).

--language|-g

Language to query labels and descriptions in. Set to the locale by default. This option is currentl only used on lookup mode.

--color|-C

By default output is colored if writing to a terminal. Disable this with --no-color or force color with --color or -C.

--api URL

SPARQL endpoint. Default value: https://query.wikidata.org/bigdata/namespace/wdq/sparql

--no-execute|-n

Don't execute query but show it in expanded form. Useful to validate and pretty-print queries.

--help|-h|-?

Show usage help

--ontology

Show information about the RDF ontology used in Wikibase

--prefixes

Show the default prefixes

--no-default-prefixes

Don't add default namespace prefixes to the SPARQL query

--man

Show detailled manual

--version|-V

Show version if this script

COPYRIGHT AND LICENSE

Copyright by Jakob Voss voss@gbv.de

Based on a PHP script by Marius Hoch hoo@online.de at https://github.com/mariushoch/asparagus.

Licensed under GPL 2.0+