Skip to content

Getting Started

Establishing the connection to a TigerGraph database

First, import pyTigerGraph:

import pyTigerGraph as tg

The functionality of pyTigerGraph is implemented by the TigerGraphConnection class. To establish the connection, instantiate the class:

conn = tg.TigerGraphConnection(<parameters>)

The constuctor has following parameters:

  • host: The IP address or hostname of the TigerGraph server, including the scheme (http or https). Default: http://localhost.
  • graphname: The default graph for running queries. Default: MyGraph.
  • username: The username on the TigerGraph server. Default: tigergraph.
  • password: The password for that user. Default: tigergraph.
  • restppPort: The post for REST++ queries. Default: 9000.
  • gsPort: The port of all other queries. Default: 14240.
  • apiToken: A token to use when making queries. No default value. Required to upsert or delete data in garph. Ignored if REST++ authentication is not enabled. See Additional Info below.
  • gsqlVersion: The version of GSQL client to be used. Default: same as database version. See GSQL Submodule for more details.
  • useCert: True if SSL certificate is required for connection. Default: True See Additional Info below.
  • certPath: The location/directory and the name of the SSL certification file where the certification should be stored. Default: ~/.gsql/my-cert.txt See Additional Info below.

Connection Clarification

Operations that DO NOT need a Token

Viewing the schema of your graph using functions such as getSchema and getVertexTypes does not require you to have an authentication token. A token is also not required to run gsql commands through pyTigerGraph.

Sample Connection

conn = tg.TigerGraphConnection(host='', username='tigergraph' password='password' graphname='DemoGraph')

Operations that DO need a Token

A token is required to view or modify any actual DATA in the graph. Examples are: upserting data, deleting edges, and getting stats about any loaded vertices. A token is also required to get version data about the TigerGraph instance.

Sample Connection

conn = tg.TigerGraphConnection(host='', username='tigergraph' password='password' graphname='DemoGraph', apiToken='av1im8nd2v06clbnb424jj7fp09hp049')

Additional Info

  • As pyTigerGraph is communicating with the TigerGraph database through REST APIs, there is no real "connection". Most (but not all) function of pyTigerGraph sends (one or more) HTTP(s) request to the REST API and processes the data returned (typically a JSON response). Thus there is no "connection" that needs to be opened and then closed down. Instantiating pyTigerGraph simply means to provide the neccesary information to be able to send the requests and receive and response.
  • See the Token Management page for information on how authentication works and how to retrieve and manage API tokens.
  • If the TigerGraph database uses encrypted connections (e.g. TigerGraph could instances), then you need to provide an SSL certificate for your connections. In this case you need to specify useCert=True and the location of the SSL certificate in certPath. pyTigerGraph will generate and download a self-signed SSL certificate for you. If useCert=False or certPath is not set, pyTigerGraph will try to connect without certificate. useCert should be False if you connect to an unsecure server such as a TigerGraph Developer instance.
  • NOTE: This functionality is not tested and most likely does not work on Windows. We intend to fix this; help is welcome (it seems all contributors are using Macs).

GSQL 101 With pyTigerGraph

Checkout this example for completing the GSQL 101 course in a Jupyter Notebook environment. Through this, you will also learn of various pyTigerGraph methods that you can use.