SQLAlchemy Trino Dialect

0.5.0 · deprecated · verified Sat Apr 11

sqlalchemy-trino was a Trino (f.k.a. PrestoSQL) dialect for SQLAlchemy. As of version 0.5.0, this project is officially deprecated. Its functionality has been merged into the upstream `trino-python-client` project, which now provides a built-in SQLAlchemy dialect. This library is no longer actively developed.

Warnings

Install

Imports

Quickstart

Demonstrates how to connect to a Trino server using the `sqlalchemy-trino` dialect. It's crucial to note that this library is deprecated, and the recommended method is to use the `trino[sqlalchemy]` package directly, which provides the same dialect string (`trino://`).

import os
from sqlalchemy import create_engine, text

# NOTE: This library is DEPRECATED. The recommended approach is to use trino-python-client directly.
# pip install trino[sqlalchemy]
# from sqlalchemy import create_engine
# engine = create_engine(f"trino://{os.environ.get('TRINO_USER', 'user')}@{os.environ.get('TRINO_HOST', 'localhost')}:{os.environ.get('TRINO_PORT', '8080')}/{os.environ.get('TRINO_CATALOG', 'system')}/{os.environ.get('TRINO_SCHEMA', 'runtime')}")

# Example using the deprecated sqlalchemy-trino library:

# Configure connection details via environment variables or replace directly
TRINO_USER = os.environ.get('TRINO_USER', 'test_user')
TRINO_HOST = os.environ.get('TRINO_HOST', 'localhost')
TRINO_PORT = os.environ.get('TRINO_PORT', '8080')
TRINO_CATALOG = os.environ.get('TRINO_CATALOG', 'system')
TRINO_SCHEMA = os.environ.get('TRINO_SCHEMA', 'runtime')

connection_string = (
    f"trino://{TRINO_USER}@{TRINO_HOST}:{TRINO_PORT}/{TRINO_CATALOG}/{TRINO_SCHEMA}"
)

try:
    engine = create_engine(connection_string)
    with engine.connect() as connection:
        result = connection.execute(text("SELECT 1"))
        print("Successfully connected to Trino!")
        for row in result:
            print(row)
except Exception as e:
    print(f"Error connecting to Trino: {e}")
    print("Please ensure Trino is running and connection details are correct.")

view raw JSON →