Using the AnzoGraph CLI
You can use the AZGI command line interpreter to run SPARQL commands and access data in AnzoGraph.
AnzoGraph also provides an alternate command line interface (AZGBOLT), which uses the Bolt protocol and enables you to run Cypher commands and queries against AnzoGraph data. For more information, see Using the Cypher Command Line Interface (AZGBOLT). The remainder of this section describes use of the AZGI command line interpreter for executing SPARQL commands using the SPARQL protocol.
Accessing the AZGI Client
The location of the AZGI client varies slightly by deployment method.
- Docker and Kubernetes Deployments
– You can run the AZGI CLI from the
/opt/anzograph/bin
directory. - RHEL/CentOS Deployments – Use the AZGI CLI in the
install_path/bin
directory. - AWS CloudFormation Deployments – Use the AZGI CLI
in the
/opt/anzograph/bin
directory. For security reasons, the AnzoGraph CloudFormation service does not automatically enable secure shell access to AnzoGraph instances. If you want to enable SSH access to a cluster, see How do I enable SSH access to AnzoGraph instances?
The AZGI CLI works on the SPARQL HTTPS port and is enabled only when SSL protocol is enabled. If SSL access is disabled and want to enable it so that you can use the command line, set enable_ssl_protocol=true in the AnzoGraph configuration file. See Changing System Settings for instructions.
AZGI Syntax
This section describes the available AZGI command options. To view the list of AZGI options from the command line, run azgi -help.
azgi [-f filename] [-c "command"] [-set param=value] [-h host_url] [-p port] [-u username:password] [-v] [-timer] [-raw] [-csv] [-json] [-xml] [-silent] [-nohead] [-noprogress] [-maxwid width] [-wide] [-o file] [-nossl] [-certs directory] [-context json_file]
Option | Description |
---|---|
-f filename | Runs the specified SPARQL query file. For example, the following command runs the query or queries in the query.rq file:azgi -f /home/user/query.rq |
-c "command" | Runs the command in quotation marks. For example, this command runs a query:azgi -c "select distinct ?eventname from <tickit> where {?event <eventname> ?eventname} limit 100" You can include multiple -c options to run multiple commands. For example, this command runs two queries: azgi -c "select * from <tickit> where {?s ?p ?o} limit 100" -c "select distinct ?likes from <tickit> where {?person <like> ?likes}" And this command sets the query_label configuration setting to "events" before running the query: azgi -c "set query_label to 'events'" -c "select distinct ?eventname from <tickit> where {?event <eventname> ?eventname} limit 100" |
-set param=value | Sets or changes parameter values in query files. For example this command runs the query in the query_summary.rq file with the $query parameter set to 2:azgi -set query=2 -f query_summary.rq |
-h host_url | Connects to a remote AnzoGraph server. For example, the following statement runs a query against AnzoGraph installed on host 10.104.55.27:azgi -h 10.104.55.27 -c "select * from <tickit> where {?s ?p ?o} limit 100" |
-p port | Used to connect to AnzoGraph on a non-default port. The default azgi port is 8256. |
-u username:password | Connects to the database with credentials (HTTP basic authentication). If you type -u username and exclude the password, the client prompts for the password. For example, the following command uses basic authentication to run a query:azgi -u admin:Passw0rd1 -c "select ?g where {graph ?g {?s ?p ?o}} limit 100" |
-v | Displays verbose output such as client connection details. For example:azgi -v -c "select distinct ?p from <tickit> where {<person1> ?p ?o}" Connecting to host=localhost port=8256 IPv4: connected POST /sparql HTTP/1.1 Host: Anon Accept: application/sparql-results+xml User-Agent: azgi Connection: keep-alive Content-Length: 38 Content-Type: application/sparql-query select distinct ?p from <tickit> where {<person1> ?p ?o} HTTP/1.1 200 OK Date: Tue, 30 Jun 2020 00:24:42 GMT Server: AnzoGraph Access-Control-Allow-Origin: * X-AnzoGraph-QueryExecution-Time: 20 Connection: close Content-Type: application/sparql-results+xml; charset=utf-8 ... |
-timer | Reports query execution time in milliseconds. |
-raw | Displays query results in raw XML, JSON, or CSV format, depending on what format you request. |
-csv | Displays results in CSV format. For example:azgi -csv -c "select * from <tickit> where {<person1> ?p ?o} order by ?p limit 10" p,o birthday,1939-11-19 card,3876972207981477 city,Kent dislike,jazz dislike,broadway email,Etiam.laoreet.libero@sodalesMaurisblandit.edu firstname,Rafael friend,person13826 friend,person33618 friend,person15410 |
-json | Displays results in JSON format. |
-xml | Displays results in XML format |
-silent | Suppresses the query output. |
-nohead | Suppresses headings in query results. |
-noprogress | Suppresses the progress messages that are displayed for queries that are inflight. If you specify the -o option or >> to redirect output to a file, all progress messages will also be written to the file unless you specify -noprogress. Cambridge Semantics recommends that you include -noprogress any time you output results to a file. |
-maxwid width | Overrides the default maximum column width of 50 characters for tabular query results. For example, for a data set with long graph names, you can expand column width to view the entire name:azgi -maxwid 10000 -c "select ?g where {graph ?g {?s ?p ?o}} limit 100" Using the -wide option described below is equivalent to "maxwid 60000." |
-wide | Increases the column width for tabular query results from the default 50 characters to 60,000 characters. Equivalent to -maxwid 60000 . |
-nossl | Instructs the client to make a non-SSL (HTTP) connection to the database. When using AZGI to send a request to a remote AnzoGraph server, include the -h host_url and -p port options when using -nossl. The default HTTP port is 7070. For example:azgi -nossl -h 10.100.0.20 -p 7070 -c "select (count(*) as ?cnt) where {?s ?p ?o}" |
-o file | Writes the response to the specified file. If the file exists, it is overwritten. When you specify this option to redirect output to a file, all progress messages will also be written to the file unless you also specify the -noprogress option. Cambridge Semantics recommends that you include -noprogress any time you output results to a file. |
-certs directory | Instructs the client to make a certified secure connection to the database. The AnzoGraph certificates are ca.crt, serv.crt (public key), and serv.key (private key) in the opt/anzograph/config directory. When sending requests to a remote AnzoGraph server, you can copy the AnzoGraph certificates to the server where you are using AZGI. For example, the following command runs a query on a remote AnzoGraph server. The command makes a certified connection using the AnzoGraph certificates, which were copied to the /home/user/certs directory:azgi -h 10.10.10.01 -certs /home/user/certs -c "select ?g where {graph ?g {?s ?p ?o}} limit 100" This command runs the same query from the AnzoGraph server. azgi -certs /opt/anzograph/config -c "select ?g where {graph ?g {?s ?p ?o}} limit 100" |
-context json_file | Specifies the query context file to use with the request. Context files are JSON-formatted files with key-value pairs that provide connection details, such as user credentials, keys, and tokens, for authentication against data sources. For more information about contexts, see Using Query Contexts. |