SPARQL command-line client based on rdflib and SPARQLWrapper.
python3 -m pip install --user git+https://github.com/FrankGrimm/sparqlcli/
Make sure pip is installed and $HOME/.local/bin/ is in your PATH.
sparqlcli endpoint
Where endpoint is either a remote SPARQL endpoint URI or a local filename.
[-f,--format]one ofhtml,hturtle,mdata,microdata,n3,nquads,nt,rdfa,rdfa1.0,rdfa1.1,trix,turtle,xmlMay be used to avoid format auto-detection whenendpointis a local file.[-r,--remote]Force treatingendpointas a remote SPARQL server.[-i,--interactive INTERACTIVE]Boolean, normally auto-detected if a tty is present.[-o,--output]output format, one oftable,json,csv, defaults to table display.- non-standard prefixes can be registered via
--prefix=longformas well, e.g.--foaf=http://xmlns.com/foaf/0.1/
Load local file testdata/demo.nt with n-triple format and pre-register the foaf namespace:
sparqlcli "testdata/demo.nt" "--format=nt" "--foaf=http://xmlns.com/foaf/0.1/"Same as the above with a single query and output type CSV (useful for scripting):
echo "SELECT DISTINCT ?pers WHERE { ?pers rdf:type foaf:Person }" | sparqlcli "testdata/demo.nt" --format=nt "--foaf=http://xmlns.com/foaf/0.1/" --output=csvQuery a remote dbpedia endpoint:
sparqlcli "http://dbpedia.org/sparql"Query a remote dbpedia endpoint and output data as json:
echo "SELECT DISTINCT ?a ?b WHERE { ?a rdf:type ?b } LIMIT 5" | sparqlcli "http://dbpedia.org/sparql" --output=jsonThe REPL features basic auto-complete on standard SPARQL keywords and previous results.
Queries and commands are sent whenever a newline (press Return twice) is encountered or the current input ends with a ;.
In interactive mode, the following commands are available in addition to simple queries:
.editopen current query buffer in$EDITOR(defaults tovim).file <filename>load and execute query from<filename>.watch <filename>poll<filename>for changes and continously execute queries.prefixes- up/down arrow keys: navigate through the query history
