Connecting to TigerGraph

Having installed pyTigerGraph, the next step is to connect to a running TigerGraph instance to access and make changes to your graph data.


  • pyTigerGraph is installed on your machine.

  • You have access to a running TigerGraph instance.

Connect to a secured TigerGraph instance

pyTigerGraph connects to the TigerGraph database through various REST API endpoints. Some endpoints use basic (username/password) authentication; others use bearer token authentication. Therefore, to access a secured TigerGraph instance, you need to provide credentials for both authentication schemes:

conn = tg.TigerGraphConnection(host="<hostname>", graphname="<graph_name>", username="<username>", password="<password>") (1)
conn.getToken(<secret>) (2)
1 The username and password are provided via the constructor of the TigerGraphConnection class.
2 The token for the bearer authentication scheme is not provided directly. Instead, you need a secret to get a session token. Secrets are unique strings that serve as a user’s credentials in certain circumstances.

In addition to these, you need to provide the hostname or IP address of the TigerGraph instance and the name of a graph.

The graph in this context is a logical container that consists of object type definitions (vertex and edge types, user-defined types (UDTs), data sources, etc.) and the instances of these object types. A TigerGraph instance can contain multiple graphs, so you need to specify which one you want to use.

For example:

conn = tg.TigerGraphConnection("", "GoodsDelivery", "hsolo", "f4lc0n")

In this command, the user is connecting to the host and accessing the GoodsDelivery graph, providing the username hsolo and corresponding password f4lc0n as well as the secret for the bearer token authentication scheme.

Connect to an unsecured instance

If your instance does not have user authentication enabled, then you do not need to specify a username, password, or authentication token:

conn = tg.TigerGraphConnection("", "GoodsDelivery")

If you are running TigerGraph locally on a virtual machine or a container with default port mapping, and you are using the default graph MyGraph, you can omit all arguments when calling the constructor:

conn = tg.TigerGraphConnection()

For more connection options, see the complete parameter list of the constructor of the TigerGraphConnection class.

Once you have established the connection, you can start using all functions offered by pyTigerGraph:

veggies = conn.getVertices("products", where="category=vegetable"))
results = conn.runInstalledQuery("shortest_delivery", {"warehouse": 1234, "store": 5678})