TuringDB Python SDK
The TuringDB Python SDK provides an easy interface for connecting to your local TuringDB server, running queries, and managing graphs programmatically.Install the PythonSDK:Using
uv package manager (you will need to create a project first):
pip:
Getting Started
Client backends
TuringDB(...) is a facade over three interchangeable backends, chosen with the type argument (or the TURINGDB_TYPE environment variable, default "json"):
Both
json and native talk to a daemon over HTTP; they differ in the wire encoding (JSON vs. binary). embedded runs the engine in-process with no network at all.
list_available_graphs() and the S3 helpers (s3_connect, transfer) are only supported on the default JSON backend (type="json").Core Methods
list_available_graphs() → list[str]
Returns the graphs persisted on disk in the TuringDB data directory (JSON backend only).
list_loaded_graphs() → list[str]
Returns the currently loaded graphs in memory.
create_graph(graph_name: str)
Creates a new empty graph with the specified name.
Internally executes CREATE GRAPH "graph_name"
load_graph(graph_name: str, raise_if_loaded: bool = True)
Loads a previously created graph into memory.
raise_if_loaded=False, it will silently continue if the graph is already loaded.
query(query: str) → pandas.DataFrame
Runs a Cypher query on the current graph.
pandas.DataFrame, with automatic typing and parsing.
query_raw(query: str) → dict
Like query, but returns the raw server response as a dict instead of a DataFrame. Useful for inspecting result metadata or column dtypes directly.
get_graph() → str / set_graph(graph_name: str)
Get or set the active graph for subsequent queries.
is_graph_loaded() → bool
Returns whether the current graph is loaded in memory.
new_change() → int
Creates a new isolated change (equivalent to CHANGE NEW), makes it the active change, and returns its integer ID.
There is no
submit() method — submit a change by running client.query("CHANGE SUBMIT").Version Control Helpers
TuringDB supports snapshot isolation and versioned commits. Use the following helpers to navigate graph history or work in isolated changes:checkout(change: int | str = "main", commit: str = "HEAD")
Switches the working context to a specific change or commit.
change: change ID or"main"commit: commit hash or"HEAD"
set_commit(commit: str)
Manually set the commit hash to use.
set_change(change: int | str)
Manually set the change ID to use (accepts int or hex string).
set_graph(graph_name: str)
Change the current graph context.
current_graph, current_commit (default "HEAD"), and current_change (default "main") properties.
Connection & Timing Helpers
reconnect()
Resets the connection. A no-op for the HTTP and embedded backends; reopens the socket for the native backend.
try_reach(timeout: int = 5) / warmup(timeout: int = 5)
Probe connectivity (try_reach) or warm the connection with a lightweight query (warmup).
get_query_exec_time() → float | None / get_total_exec_time() → float | None
Return the server-side execution time and the full round-trip time (in milliseconds) of the last query.
S3 / Data Transfer
These helpers move graph data between local paths, S3, and the TuringDB server. They are only available on the JSON backend (type="json").
s3_connect(bucket_name, access_key=None, secret_key=None, region=None, use_scratch=True)
Connect an S3 client for transfers. Credentials are optional — if omitted, the machine’s configured AWS credentials are used.
transfer(src, dst)
Transfer data between a local path, an s3://… URI, or a turingdb://… path. The direction and mechanism are inferred from the URI schemes.
query) are S3 CONNECT "<key>" "<secret>" "<region>", S3 PULL "<s3-url>" "<dst>", and S3 PUSH "<src>" "<s3-url>".
Response Format
All queries return apandas.DataFrame, typed according to schema:
Error Handling
All SDK errors raise a customTuringDBException.
Example Workflow
Notes
- The JSON backend (
type="json") useshttpx; thenativeandembeddedbackends use a compiled extension - Only the graph name, change ID, and commit hash are sent with HTTP requests
- The SDK supports the full TuringDB Cypher dialect, including matching by internal node ID (
WHERE n = 1234) and versioned queries against past commits

