|
1 | 1 | # pyTigerGraph |
2 | 2 |
|
3 | | -pyTigerGraph is a Python package for connecting to TigerGraph databases. Check out the documentation [here](https://docs.tigergraph.com/pytigergraph/current/intro/). |
| 3 | +pyTigerGraph is a Python client for [TigerGraph](https://www.tigergraph.com/) databases. It wraps the REST++ and GSQL APIs and provides both a synchronous and an asynchronous interface. |
4 | 4 |
|
5 | | -[](https://pepy.tech/project/pyTigergraph) |
6 | | -[](https://pepy.tech/project/pyTigergraph) |
7 | | -[](https://pepy.tech/project/pyTigergraph) |
| 5 | +Full documentation: <https://docs.tigergraph.com/pytigergraph/current/intro/> |
8 | 6 |
|
9 | | -## Quickstart |
| 7 | +Downloads: [](https://pepy.tech/project/pyTigergraph) | [](https://pepy.tech/project/pyTigergraph) | [](https://pepy.tech/project/pyTigergraph) |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +### Base package |
10 | 14 |
|
11 | | -### Installing pyTigerGraph |
12 | | -This section walks you through installing pyTigerGraph on your machine. |
| 15 | +```sh |
| 16 | +pip install pyTigerGraph |
| 17 | +``` |
13 | 18 |
|
14 | | -#### Prerequisites |
15 | | -* Python 3+ |
16 | | -* If you wish to use the GDS functionality, install `torch` ahead of time. |
| 19 | +### Optional extras |
17 | 20 |
|
18 | | -#### Install _pyTigerGraph_ |
| 21 | +| Extra | What it adds | Install command | |
| 22 | +|-------|-------------|-----------------| |
| 23 | +| `gds` | Graph Data Science — data loaders for PyTorch Geometric, DGL, and Pandas | `pip install 'pyTigerGraph[gds]'` | |
| 24 | +| `mcp` | Model Context Protocol server — installs [`pyTigerGraph-mcp`](https://github.com/tigergraph/tigergraph-mcp) (convenience alias) | `pip install 'pyTigerGraph[mcp]'` | |
| 25 | +| `fast` | [orjson](https://github.com/ijl/orjson) JSON backend — 2–10× faster parsing, releases the GIL under concurrent load | `pip install 'pyTigerGraph[fast]'` | |
19 | 26 |
|
20 | | -To download _pyTigerGraph_, run the following command in the command line or use the appropriate tool of your development environment (anaconda, PyCharm, etc.).: |
| 27 | +Extras can be combined: |
21 | 28 |
|
22 | 29 | ```sh |
23 | | -pip3 install pyTigerGraph |
| 30 | +pip install 'pyTigerGraph[fast,gds,mcp]' |
24 | 31 | ``` |
25 | 32 |
|
26 | | -#### Install _pyTigerGraph[gds]_ |
| 33 | +#### `[gds]` prerequisites |
27 | 34 |
|
28 | | -To utilize the Graph Data Science Functionality, there are a few options: |
29 | | -* To use the GDS functions with **PyTorch Geometric**, install `torch` and `PyTorch Geometric` according to their instructions: |
| 35 | +Install `torch` before installing the `gds` extra: |
30 | 36 |
|
31 | | - 1) [Install Torch](https://pytorch.org/get-started/locally/) |
| 37 | +1. [Install Torch](https://pytorch.org/get-started/locally/) |
| 38 | +2. Optionally [Install PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html) or [Install DGL](https://www.dgl.ai/pages/start.html) |
| 39 | +3. `pip install 'pyTigerGraph[gds]'` |
32 | 40 |
|
33 | | - 2) [Install PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html) |
| 41 | +#### `[fast]` — orjson JSON backend |
34 | 42 |
|
35 | | - 3) Install pyTigerGraph with: |
36 | | - ```sh |
37 | | - pip3 install 'pyTigerGraph[gds]' |
38 | | - ``` |
| 43 | +`orjson` is a Rust-backed JSON library that is detected and used automatically when installed. No code changes are required. It improves throughput in two ways: |
39 | 44 |
|
40 | | -* To use the GDS functions with **DGL**, install `torch` and `dgl` according to their instructions: |
| 45 | +- **Faster parsing** — 2–10× vs stdlib `json` |
| 46 | +- **GIL release** — threads parse responses concurrently instead of serialising on the GIL |
41 | 47 |
|
42 | | - 1) [Install Torch](https://pytorch.org/get-started/locally/) |
| 48 | +If `orjson` is not installed the library falls back to stdlib `json` transparently. |
43 | 49 |
|
44 | | - 2) [Install DGL](https://www.dgl.ai/pages/start.html) |
| 50 | +--- |
45 | 51 |
|
46 | | - 3) Install pyTigerGraph with: |
47 | | - ```sh |
48 | | - pip3 install 'pyTigerGraph[gds]' |
49 | | - ``` |
| 52 | +## Quickstart |
50 | 53 |
|
51 | | -* To use the GDS functions without needing to produce output in the format supported by PyTorch Geometric or DGL. |
52 | | -This makes the data loaders output *Pandas dataframes*: |
53 | | -```sh |
54 | | -pip3 install 'pyTigerGraph[gds]' |
| 54 | +### Synchronous connection |
| 55 | + |
| 56 | +```python |
| 57 | +from pyTigerGraph import TigerGraphConnection |
| 58 | + |
| 59 | +conn = TigerGraphConnection( |
| 60 | + host="http://localhost", |
| 61 | + graphname="my_graph", |
| 62 | + username="tigergraph", |
| 63 | + password="tigergraph", |
| 64 | +) |
| 65 | + |
| 66 | +print(conn.echo()) |
55 | 67 | ``` |
56 | 68 |
|
57 | | -Once the package is installed, you can import it like any other Python package: |
| 69 | +Use as a context manager to ensure the underlying HTTP session is closed: |
58 | 70 |
|
59 | | -```py |
60 | | -import pyTigerGraph as tg |
| 71 | +```python |
| 72 | +with TigerGraphConnection(host="http://localhost", graphname="my_graph") as conn: |
| 73 | + result = conn.runInstalledQuery("my_query", {"param": "value"}) |
61 | 74 | ``` |
62 | | -### Getting Started with Core Functions |
| 75 | + |
| 76 | +### Asynchronous connection |
| 77 | + |
| 78 | +`AsyncTigerGraphConnection` exposes the same API as `TigerGraphConnection` but with `async`/`await` syntax. It uses [aiohttp](https://docs.aiohttp.org/) internally and shares a single connection pool across all concurrent tasks, making it significantly more efficient than threaded sync code at high concurrency. |
| 79 | + |
| 80 | +```python |
| 81 | +import asyncio |
| 82 | +from pyTigerGraph import AsyncTigerGraphConnection |
| 83 | + |
| 84 | +async def main(): |
| 85 | + async with AsyncTigerGraphConnection( |
| 86 | + host="http://localhost", |
| 87 | + graphname="my_graph", |
| 88 | + username="tigergraph", |
| 89 | + password="tigergraph", |
| 90 | + ) as conn: |
| 91 | + result = await conn.runInstalledQuery("my_query", {"param": "value"}) |
| 92 | + print(result) |
| 93 | + |
| 94 | +asyncio.run(main()) |
| 95 | +``` |
| 96 | + |
| 97 | +### Token-based authentication |
| 98 | + |
| 99 | +```python |
| 100 | +conn = TigerGraphConnection( |
| 101 | + host="http://localhost", |
| 102 | + graphname="my_graph", |
| 103 | + gsqlSecret="my_secret", # generates a session token automatically |
| 104 | +) |
| 105 | +``` |
| 106 | + |
| 107 | +### HTTPS / TigerGraph Cloud |
| 108 | + |
| 109 | +```python |
| 110 | +conn = TigerGraphConnection( |
| 111 | + host="https://my-instance.i.tgcloud.io", |
| 112 | + graphname="my_graph", |
| 113 | + username="tigergraph", |
| 114 | + password="tigergraph", |
| 115 | + tgCloud=True, |
| 116 | +) |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Connection parameters |
| 122 | + |
| 123 | +| Parameter | Type | Default | Description | |
| 124 | +|-----------|------|---------|-------------| |
| 125 | +| `host` | `str` | `"http://127.0.0.1"` | Server URL including scheme (`http://` or `https://`) | |
| 126 | +| `graphname` | `str` | `""` | Target graph name | |
| 127 | +| `username` | `str` | `"tigergraph"` | Database username | |
| 128 | +| `password` | `str` | `"tigergraph"` | Database password | |
| 129 | +| `gsqlSecret` | `str` | `""` | GSQL secret for token-based auth (preferred over username/password) | |
| 130 | +| `apiToken` | `str` | `""` | Pre-obtained REST++ API token | |
| 131 | +| `jwtToken` | `str` | `""` | JWT token for customer-managed authentication | |
| 132 | +| `restppPort` | `int\|str` | `"9000"` | REST++ port (auto-fails over to `14240/restpp` for TigerGraph 4.x) | |
| 133 | +| `gsPort` | `int\|str` | `"14240"` | GSQL server port | |
| 134 | +| `certPath` | `str` | `None` | Path to CA certificate for HTTPS | |
| 135 | +| `tgCloud` | `bool` | `False` | Set to `True` for TigerGraph Cloud instances | |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Performance notes |
| 140 | + |
| 141 | +### Synchronous mode (`TigerGraphConnection`) |
| 142 | + |
| 143 | +- Each thread gets its own dedicated HTTP session and connection pool, so concurrent threads never block each other. |
| 144 | +- Install `pyTigerGraph[fast]` to activate the `orjson` backend and reduce JSON parsing overhead under concurrent load. |
| 145 | +- Use `ThreadPoolExecutor` to run queries in parallel: |
| 146 | + |
| 147 | +```python |
| 148 | +from concurrent.futures import ThreadPoolExecutor, as_completed |
| 149 | + |
| 150 | +with TigerGraphConnection(...) as conn: |
| 151 | + with ThreadPoolExecutor(max_workers=16) as executor: |
| 152 | + futures = [executor.submit(conn.runInstalledQuery, "q", {"p": v}) for v in values] |
| 153 | + for f in as_completed(futures): |
| 154 | + print(f.result()) |
| 155 | +``` |
| 156 | + |
| 157 | +### Asynchronous mode (`AsyncTigerGraphConnection`) |
| 158 | + |
| 159 | +- Uses a single `aiohttp.ClientSession` with an unbounded connection pool shared across all concurrent coroutines — no GIL, no thread-scheduling overhead. |
| 160 | +- Typically achieves higher QPS and lower tail latency than the threaded sync mode for I/O-bound workloads. |
| 161 | + |
| 162 | +```python |
| 163 | +import asyncio |
| 164 | +from pyTigerGraph import AsyncTigerGraphConnection |
| 165 | + |
| 166 | +async def main(): |
| 167 | + async with AsyncTigerGraphConnection(...) as conn: |
| 168 | + tasks = [conn.runInstalledQuery("q", {"p": v}) for v in values] |
| 169 | + results = await asyncio.gather(*tasks) |
| 170 | + |
| 171 | +asyncio.run(main()) |
| 172 | +``` |
| 173 | + |
| 174 | +--- |
| 175 | + |
| 176 | +## Graph Data Science (GDS) |
| 177 | + |
| 178 | +The `gds` sub-module provides data loaders that stream vertex and edge data from TigerGraph directly into PyTorch Geometric, DGL, or Pandas DataFrames for machine learning workflows. |
| 179 | + |
| 180 | +Install requirements, then access via `conn.gds`: |
| 181 | + |
| 182 | +```python |
| 183 | +conn = TigerGraphConnection(host="...", graphname="...") |
| 184 | +loader = conn.gds.vertexLoader(attributes=["feat", "label"], batch_size=1024) |
| 185 | +for batch in loader: |
| 186 | + train(batch) |
| 187 | +``` |
| 188 | + |
| 189 | +See the [GDS documentation](https://docs.tigergraph.com/pytigergraph/current/gds/) for full details. |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +## MCP Server |
| 194 | + |
| 195 | +The TigerGraph MCP server is now a standalone package: **[pyTigerGraph-mcp](https://github.com/tigergraph/tigergraph-mcp)**. It exposes TigerGraph operations as tools for AI agents and LLM applications (Claude Desktop, Cursor, Copilot, etc.). |
| 196 | + |
| 197 | +```sh |
| 198 | +# Recommended — install the standalone package directly |
| 199 | +pip install pyTigerGraph-mcp |
| 200 | + |
| 201 | +# Or via the pyTigerGraph convenience alias (installs pyTigerGraph-mcp automatically) |
| 202 | +pip install 'pyTigerGraph[mcp]' |
| 203 | + |
| 204 | +# Start the server (reads connection config from environment variables) |
| 205 | +tigergraph-mcp |
| 206 | +``` |
| 207 | + |
| 208 | +For full setup instructions, available tools, configuration examples, and multi-profile support, see the **[pyTigerGraph-mcp README](https://github.com/tigergraph/tigergraph-mcp#readme)**. |
| 209 | + |
| 210 | +> **Migrating from `pyTigerGraph.mcp`?** Update your imports: |
| 211 | +> ```python |
| 212 | +> # Old |
| 213 | +> from pyTigerGraph.mcp import serve, ConnectionManager |
| 214 | +> # New |
| 215 | +> from tigergraph_mcp import serve, ConnectionManager |
| 216 | +> ``` |
| 217 | +
|
| 218 | +--- |
| 219 | +
|
| 220 | +## Getting started video |
63 | 221 |
|
64 | 222 | [](https://www.youtube.com/watch?v=2BcC3C-qfX4) |
65 | 223 |
|
66 | | -The video above is a good starting place for learning the core functions of pyTigerGraph. [This Google Colab notebook](https://colab.research.google.com/drive/1JhYcnGVWT51KswcXZzyPzKqCoPP5htcC) is the companion notebook to the video. |
| 224 | +Companion notebook: [Google Colab](https://colab.research.google.com/drive/1JhYcnGVWT51KswcXZzyPzKqCoPP5htcC) |
| 225 | +
|
| 226 | +--- |
| 227 | +
|
| 228 | +## Links |
| 229 | +
|
| 230 | +- [Documentation](https://docs.tigergraph.com/pytigergraph/current/intro/) |
| 231 | +- [PyPI](https://pypi.org/project/pyTigerGraph/) |
| 232 | +- [GitHub Issues](https://github.com/tigergraph/pyTigerGraph/issues) |
| 233 | +- [Source](https://github.com/tigergraph/pyTigerGraph) |
0 commit comments