Skip to main content

Python ADBC driver for GizmoSQL with OAuth/SSO support

Project description

adbc-driver-gizmosql

A Python ADBC driver for GizmoSQL with OAuth/SSO support

adbc-driver-gizmosql-ci Supported Python Versions PyPI version PyPI Downloads

Overview

adbc-driver-gizmosql is a lightweight Python wrapper around adbc-driver-flightsql that adds GizmoSQL-specific features:

  • OAuth/SSO browser flow — Authenticate via your identity provider (Google, Okta, etc.) with a single parameter change
  • DBAPI 2.0 interface — Drop-in replacement for adbc_driver_flightsql.dbapi
  • Zero extra dependencies — OAuth flow uses only Python stdlib; the only dependency is adbc-driver-flightsql

Setup (to run locally)

Install Python package

You can install adbc-driver-gizmosql from PyPi or from source.

Option 1 - from PyPi

# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
. .venv/bin/activate

pip install adbc-driver-gizmosql

Option 2 - from source - for development

git clone https://github.com/gizmodata/adbc-driver-gizmosql

cd adbc-driver-gizmosql

# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
. .venv/bin/activate

# Upgrade pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel

# Install adbc-driver-gizmosql - in editable mode with dev and test dependencies
pip install --editable ".[dev,test]"

Usage

Start a GizmoSQL server

First — start a GizmoSQL server in Docker (mounts a small TPC-H database by default):

docker run --name gizmosql \
           --detach \
           --rm \
           --tty \
           --init \
           --publish 31337:31337 \
           --env TLS_ENABLED="1" \
           --env GIZMOSQL_USERNAME="gizmosql_user" \
           --env GIZMOSQL_PASSWORD="gizmosql_password" \
           --env PRINT_QUERIES="1" \
           --pull missing \
           gizmodata/gizmosql:latest

Password authentication

from adbc_driver_gizmosql import dbapi as gizmosql

with gizmosql.connect("grpc+tls://localhost:31337",
                      username="gizmosql_user",
                      password="gizmosql_password",
                      tls_skip_verify=True,
                      ) as conn:
    with conn.cursor() as cur:
        cur.execute("SELECT n_nationkey, n_name FROM nation WHERE n_nationkey = ?",
                    parameters=[24])
        table = cur.fetch_arrow_table()
        print(table)

DDL/DML — execute immediately without fetching

GizmoSQL uses a lazy-execution model, so a plain cursor.execute() for DDL/DML requires a subsequent fetch to actually fire the statement on the server. cursor.execute_update() bypasses this by calling the server's DoPutPreparedStatementUpdate RPC directly, executing the statement immediately and returning the number of rows affected:

from adbc_driver_gizmosql import dbapi as gizmosql

with gizmosql.connect("grpc+tls://localhost:31337",
                      username="gizmosql_user",
                      password="gizmosql_password",
                      tls_skip_verify=True,
                      ) as conn:
    with conn.cursor() as cur:
        # DDL — returns 0 (no rows affected)
        cur.execute_update("CREATE TABLE t (a INT)")

        # DML — returns the number of rows affected
        rows_affected = cur.execute_update("INSERT INTO t VALUES (1)")
        print(f"Rows affected: {rows_affected}")

OAuth/SSO authentication

When your GizmoSQL server is configured with OAuth, simply change auth_type:

from adbc_driver_gizmosql import dbapi as gizmosql

with gizmosql.connect("grpc+tls://gizmosql.example.com:31337",
                      auth_type="external",
                      tls_skip_verify=True,
                      ) as conn:
    with conn.cursor() as cur:
        cur.execute("SELECT CURRENT_USER AS user")
        print(cur.fetch_arrow_table())

This will:

  1. Auto-discover the OAuth server endpoint
  2. Open your browser to the identity provider login page
  3. Poll for completion and retrieve the identity token
  4. Connect to GizmoSQL using the token via Basic Auth (username="token")

Advanced: Standalone OAuth token retrieval

from adbc_driver_gizmosql import get_oauth_token

result = get_oauth_token(
    host="gizmosql.example.com",
    port=31339,           # OAuth HTTP port (default)
    tls_skip_verify=True, # Skip TLS cert verification
    timeout=300,          # Seconds to wait for user to complete auth
)

print(f"Token: {result.token}")
print(f"Session: {result.session_uuid}")

Bulk ingest (load Arrow data into a table)

The ADBC adbc_ingest method on the cursor lets you load Arrow tables, record batches, or record batch readers directly into GizmoSQL — no row-by-row INSERT needed:

import pyarrow as pa
from adbc_driver_gizmosql import dbapi as gizmosql

# Build an Arrow table
table = pa.table({
    "id": [1, 2, 3],
    "name": ["Alice", "Bob", "Charlie"],
    "score": [95.0, 87.5, 91.2],
})

with gizmosql.connect("grpc+tls://localhost:31337",
                      username="gizmosql_user",
                      password="gizmosql_password",
                      tls_skip_verify=True,
                      ) as conn:
    with conn.cursor() as cur:
        # Create a new table and insert the data
        cur.adbc_ingest("students", table, mode="create")

        # Verify
        cur.execute("SELECT * FROM students")
        print(cur.fetch_arrow_table())

Supported modes: "create", "append", "replace", "create_append".

Pandas integration

import pandas as pd
from adbc_driver_gizmosql import dbapi as gizmosql

with gizmosql.connect("grpc+tls://localhost:31337",
                      username="gizmosql_user",
                      password="gizmosql_password",
                      tls_skip_verify=True,
                      ) as conn:
    df = pd.read_sql("SELECT * FROM nation ORDER BY n_nationkey", conn)
    print(df)

API Reference

dbapi.connect()

Parameter Type Default Description
uri str required Flight SQL URI (e.g., "grpc+tls://host:31337")
username str None Username for password auth
password str None Password for password auth
tls_skip_verify bool False Skip TLS cert verification
auth_type str "password" "password" or "external" (OAuth)
oauth_port int 31339 OAuth HTTP server port
oauth_url str None Explicit OAuth base URL
oauth_tls_skip_verify bool None TLS skip for OAuth (defaults to tls_skip_verify)
oauth_timeout int 300 Seconds to wait for OAuth
open_browser bool True Auto-open browser for OAuth
db_kwargs dict None Extra ADBC database options
conn_kwargs dict None Extra ADBC connection options
autocommit bool True Enable autocommit

cursor.execute_update()

Execute a DDL/DML statement immediately without fetching. Use this instead of cursor.execute() for statements that don't return result sets — it fires the statement on the server right away, bypassing GizmoSQL's lazy-execution model.

Parameter Type Default Description
query str required SQL DDL or DML statement to execute

Returns: int — number of rows affected (0 for DDL statements that do not affect rows)

Note: The module-level gizmosql.execute_update(cursor, query) function is still available for backward compatibility but new code should use cursor.execute_update(query).

get_oauth_token()

Parameter Type Default Description
host str required GizmoSQL server hostname
port int 31339 OAuth HTTP port
tls_skip_verify bool True Skip TLS cert verification
timeout int 300 Seconds to wait
poll_interval float 1 Seconds between polls
open_browser bool True Auto-open browser
oauth_url str None Explicit OAuth base URL

Returns: OAuthResult(token=str, session_uuid=str)

How the OAuth flow works

Python Client              GizmoSQL OAuth Server         Identity Provider
     |                            |                            |
     +-- GET /oauth/initiate ---->|                            |
     |<-- {uuid, auth_url} -------|                            |
     |                            |                            |
     +-- Open browser to auth_url-|--------------------------->|
     |                            |                            |
     |                            |<-- callback (auth code) ---|
     |                            |-- exchange code for token ->|
     |                            |<-- id_token ---------------|
     |                            |                            |
     +-- GET /oauth/token/{uuid}->|                            |
     |<-- {status: complete,      |                            |
     |     token: <id_token>}     |                            |
     |                            |                            |
     +-- Flight BasicAuth ------->|                            |
     |   user="token"             | (verify token via JWKS,    |
     |   pass=<id_token>          |  issue server JWT)         |
     |<-- Server Bearer token ----|                            |

Handy development commands

Version management

Bump the version of the application - (you must have installed from source with the [dev] extras)

bumpver update --patch

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

adbc_driver_gizmosql-1.0.5.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

adbc_driver_gizmosql-1.0.5-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file adbc_driver_gizmosql-1.0.5.tar.gz.

File metadata

  • Download URL: adbc_driver_gizmosql-1.0.5.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adbc_driver_gizmosql-1.0.5.tar.gz
Algorithm Hash digest
SHA256 3cfd4ad4cfe69fbe30eea76347124b6510fbd440a667abcee54d8a400c8478e1
MD5 9210a8b5bf0e2dee932e9a19e4e03b0c
BLAKE2b-256 e95822369873dd22480558d59de09ff48ec895a8ba280acaf728fcdda01fa0a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for adbc_driver_gizmosql-1.0.5.tar.gz:

Publisher: ci.yml on gizmodata/adbc-driver-gizmosql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adbc_driver_gizmosql-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for adbc_driver_gizmosql-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6803436f0e962cde2babd67c49948987ddc46ed385e60fa24a00413ac7444848
MD5 c8f780b8ee669cf4603b3f7942ecb70e
BLAKE2b-256 043362f83c6894d17e9e35a355ce109967b4c44ee764659b06b162fe184cfdfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for adbc_driver_gizmosql-1.0.5-py3-none-any.whl:

Publisher: ci.yml on gizmodata/adbc-driver-gizmosql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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