Python SDK Reference
pygnok is the standalone Python client for external scripts. Gnok support provides the package when your client connectivity is set up (email support@gnok.io); see installation and connection setup.
Use the pre-installed gnok helper instead — it
auto-connects as the signed-in user (no connect(), no token) and adds a
gnok.ml namespace to register trained models for SQL inference. gnok wraps
pygnok.
pygnok.connect()
Create a connection to Gnok. The signature below shows selected SDK defaults, not hosted connection values: always pass the host, port, and token provided for your organization, and tls=True.
pygnok.connect(
host: str = "localhost",
port: int = 50070,
token: str | None = None,
tls: bool = False,
tls_root_certs: bytes | None = None,
connect_timeout: float = 10.0,
query_timeout: float = 300.0,
) -> Connection
| Parameter | Type | Default | Description |
|---|---|---|---|
host | str | "localhost" | Flight SQL host provided for your organization. Always set it. |
port | int | 50070 | Port provided for your organization. Always set it. |
token | str | None | JWT bearer token |
tls | bool | False | Set True for the hosted TLS endpoint |
tls_root_certs | bytes | None | Optional CA certificates supplied for your endpoint |
connect_timeout | float | 10.0 | Connection timeout in seconds |
query_timeout | float | 300.0 | Query timeout in seconds |
Connection
connection.cursor()
Create a new cursor for executing queries.
cursor = conn.cursor()
connection.close()
Close the connection and release resources.
Cursor
cursor.execute(sql, parameters=None)
Execute a SQL statement.
cursor.execute("SELECT * FROM orders WHERE region = ?", ["US"])
cursor.executemany(sql, seq_of_parameters)
Execute a SQL statement with multiple parameter sets.
cursor.executemany(
"INSERT INTO orders (id, amount) VALUES (?, ?)",
[(1, 99.99), (2, 149.50)]
)
cursor.fetchone()
Fetch the next row as a tuple, or None if no more rows.
cursor.fetchmany(size=cursor.arraysize)
Fetch the next size rows as a list of tuples.
cursor.fetchall()
Fetch all remaining rows as a list of tuples.
cursor.fetch_arrow_table()
Fetch all results as a PyArrow Table for zero-copy access.
table = cursor.fetch_arrow_table()
df = table.to_pandas()
cursor.description
Column metadata after executing a query:
# [(name, type_code, display_size, internal_size, precision, scale, null_ok), ...]
cursor.description
cursor.rowcount
Number of rows affected by the last DML statement, or -1 for queries.
cursor.close()
Close the cursor and release resources.