Skip to main content

GSQL and RESTPP Python remote clients for TigerGraph

Project description

gsql_client

Introduction

If you are using TigerGraph, you probably know that there are only one way to remotely execute your GSQL scripts: gql_client.jar. This jar is an interactive console and you can not programmatically access GSQL server (until 2.4 TigerGraph introduces JDBC based access). But we love Python, right?

So here we are: a Python version of gsql_client, removing all interactive features. gsql_client.jar actually uses http to interact with GSQL server. So can Python. TigerGraph already open sourced their client implementation, but only for versions later than 2.3.0. I originally wrote this for 2.2.3, so there are minor differences.

Installation

Copy gsql_client folder to your project or install with pip:

pip install gsql_client

This package has no external dependency and it is compatible with both Python 2 and 3.

Note:

if you submit large gsql files or long running commands, using remote client may receive IncompleteRead exception as TigerGraph nginx service does not properly configure the proxy_read_timeout for /gsqlserver path. So you may need to edit {TIGERGRAPH_HOME}/tigergraph/config/nginx/nginx_1.conf and add this option (like for /admin/websocket or /websocket).

TODO

Maybe I could create a main function to launch an interactive shell (using stdlib cmd module), so that we can use python -m gsql_client just as java -jar gsql_client.jar. It is best to keep them compatible (for both command line options and behaviors).

Usage

It contains mainly 2 classes: gsql_client.Client as a remote GSQL server client and gsql_client.RESTPP for directly interact with RESTPP server.

from gsql_client import Client, RESTPP

# default port 14240, you can use 10.0.0.1:29383 to specify another port
client = Client("10.0.0.1")
# for versions later than 2.4.0, it is mandatory to specify the version like this:
client = Client("10.0.0.1", version="v2_4_0")
# or the login would fail with incompatible server/client version
# you can directly specify the commit hash of the client (used for compatibility check) by:
client = Client("10.0.0.1", version="v2_6_0", commit="somehexhashstring")

client.login()  # returns True for success; exceptions and False for failure
res = client.command("ls")  # also returns the result as a list of lines
client.command("clear graph store", "y") # needs answer
client.run_file("yourfile.gsql")
client.version()
client.help()
client.quit()

restpp = RESTPP("10.0.0.1")  # default port 9000

# no need to login
# but you can use restpp.requesttoken(secret) to setup token based authentication:
secret = client.get_secret("my_graph", create_alias="my_graph_query_secret")

# use=True for directly using the requested token
token = restpp.request_token(secret, use=True)
# or with set_token
restpp.set_token(token)

# same as type `select * from MyVertex` in gsql shell
restpp.select_vertices("my_graph", "MyVertex")
restpp.query("my_graph", "my_query", param1 = 1)  # run your query

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gsql_client-0.1.6.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gsql_client-0.1.6-py2-none-any.whl (16.1 kB view details)

Uploaded Python 2

File details

Details for the file gsql_client-0.1.6.tar.gz.

File metadata

  • Download URL: gsql_client-0.1.6.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for gsql_client-0.1.6.tar.gz
Algorithm Hash digest
SHA256 12643d5b8cb2b2de91a7799a8d5f9e7ba572193e7b96c1e983daaad96e9e7411
MD5 55b23f9f0ce920e098edacc0a4bb660a
BLAKE2b-256 1449f13cf4f66936e005855907d90af830ff40a954476ae2862abc49961f4bcc

See more details on using hashes here.

File details

Details for the file gsql_client-0.1.6-py2-none-any.whl.

File metadata

  • Download URL: gsql_client-0.1.6-py2-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for gsql_client-0.1.6-py2-none-any.whl
Algorithm Hash digest
SHA256 2ccfcb9910f4d341604838ced9ce8e9ce248782c624f5b0be29f2c70d3a72cb7
MD5 586670974a936b48b3526712a267d5c8
BLAKE2b-256 3fce01b47ca5d39dd378e7737fa6e7f84d1a0521df2ee7d2b8838c984be28b0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page