SQLAlchemy Dremio

3.0.5 · active · verified Thu Apr 16

SQLAlchemy Dremio is a SQLAlchemy dialect that enables connecting to Dremio via its Apache Arrow Flight interface. It's actively maintained, with the current stable version being 3.0.5, and generally follows a release cadence tied to Dremio Flight client updates and SQLAlchemy compatibility.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to establish a connection to Dremio using `sqlalchemy-dremio` via the Flight interface and execute a basic query. It uses environment variables for secure credential handling and highlights common connection string parameters like host, port, user, password, catalog, and SSL settings.

import sqlalchemy
import os

# Configure Dremio connection details using environment variables for security
DREMIO_HOST = os.environ.get('DREMIO_HOST', 'localhost')
DREMIO_PORT = os.environ.get('DREMIO_PORT', '32010')
DREMIO_USER = os.environ.get('DREMIO_USER', 'dremio_user')
DREMIO_PASS = os.environ.get('DREMIO_PASS', 'dremio_password')
DREMIO_CATALOG = os.environ.get('DREMIO_CATALOG', 'DREMIO') # e.g., 'DREMIO' or your space name
USE_SSL = os.environ.get('DREMIO_USE_SSL', 'true').lower() == 'true'

# Construct the connection string
connection_string = (
    f"dremio+flight://{DREMIO_USER}:{DREMIO_PASS}@{DREMIO_HOST}:{DREMIO_PORT}/"
    f"{DREMIO_CATALOG}?USE_SSL={str(USE_SSL).lower()}"
)

print(f"Connecting to: {connection_string.split(DREMIO_PASS)[0]}*****@{DREMIO_HOST}:{DREMIO_PORT}/{DREMIO_CATALOG}...")

try:
    # Create the SQLAlchemy engine
    engine = sqlalchemy.create_engine(connection_string)

    # Establish a connection and execute a simple query
    with engine.connect() as connection:
        # Ensure you have a table accessible, e.g., 'sys.version'
        result = connection.execute(sqlalchemy.text("SELECT * FROM sys.version"))
        
        # Fetch and print results
        print("\nQuery Results:")
        for row in result:
            print(row)

    print("\nSuccessfully connected to Dremio and executed a query.")

except Exception as e:
    print(f"\nError connecting to Dremio or executing query: {e}")
    print("Please ensure Dremio is running, credentials are correct, ")
    print("and the Flight endpoint is accessible (often port 32010, sometimes with SSL).")

view raw JSON →