Skip to main content

Trino dialect for SQLAlchemy

Project description


Trino (f.k.a PrestoSQL) dialect for SQLAlchemy.

The primary purpose of this is provide a dialect for Trino that can be used with Apache Superset. But other use-cases should works as well.

Supported Trino version

Trino version 352 and higher


The driver can either be installed through PyPi or from the source code.

Through Python Package Index

pip install sqlalchemy-trino

Latest from Source Code

pip install git+


To connect from SQLAlchemy to Trino, use connection string (URL) following this pattern:


JWT authentication

You can pass the JWT token via either connect_args or the query string parameter accessToken:

from sqlalchemy.engine import create_engine
from trino.auth import JWTAuthentication

# pass access token via connect_args
engine = create_engine(
  connect_args={'auth': JWTAuthentication('a-jwt-token')},

# pass access token via the query string param accessToken
engine = create_engine(

Notice: When using username and password, it will connect to Trino over TLS connection automatically.

User impersonation

It supports user impersonation with username and password based authentication only.

You can pass the session user (a.k.a., the user that will be impersonated) via either connect_args or the query string parameter sessionUser:

from sqlalchemy.engine import create_engine

# pass session user via connect_args
engine = create_engine(
  connect_args={'user': 'user-to-be-impersonated'},

# pass session user via a query string parameter
engine = create_engine(

Pandas support

import pandas as pd
from pandas import DataFrame
import sqlalchemy_trino
from sqlalchemy.engine import Engine, Connection

def trino_pandas_write(engine: Engine):
    df: DataFrame = pd.read_csv("tests/data/population.csv")
    df.to_sql(con=engine, schema="default", name="abcxyz", method="multi", index=False)


def trino_pandas_read(engine: Engine):
    connection: Connection = engine.connect()
    df = pd.read_sql("SELECT * FROM public.foobar", connection)


Note: in df.to_sql following params is required:

  • index=False because index is not supported in Trino.
  • method="multi": currently method=None (default) is not working because Trino dbapi is not support executemany yet

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

sqlalchemy-trino-0.4.1.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distributions

sqlalchemy_trino-0.4.1-py3.8.egg (21.3 kB view hashes)

Uploaded Source

sqlalchemy_trino-0.4.1-py3-none-any.whl (14.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page