Skip to main content

sqlalchemy-trino

⚠️ Deprecation and Archive Notice

sqlalchemy-trino was developed as Trino (f.k.a PrestoSQL) dialect for SQLAlchemy. Since trinodb/trino-python-client#81, all code of sqlalchemy-trino is donated and merged into upstream project. So now, this project is no longer active and consider as deprecated.

Supported Trino version

Trino version 352 and higher

Installation

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+https://github.com/dungdm93/sqlalchemy-trino

Usage

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

trino://<username>:<password>@<host>:<port>/catalog/[schema]

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(
  'trino://<username>@<host>:<port>/',
  connect_args={'auth': JWTAuthentication('a-jwt-token')},
)

# pass access token via the query string param accessToken
engine = create_engine(
  'trino://<username>@<host>:<port>/?accessToken=a-jwt-token',
)

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(
  'trino://<username>:<password>@<host>:<port>/',
  connect_args={'user': 'user-to-be-impersonated'},
)

# pass session user via a query string parameter
engine = create_engine(
  'trino://<username>:<password>@<host>:<port>/?sessionUser=user-to-be-impersonated',
)

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)

    print(df)


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

    print(df)

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

Release files for sqlalchemy-trino 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-trino 0.5.0
File Size Uploaded
sqlalchemy-trino-0.5.0.tar.gz 6.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for sqlalchemy-trino 0.5.0
File Interpreter ABI Platform
sqlalchemy_trino-0.5.0-py3.9.egg Legacy Egg format - - Details
sqlalchemy_trino-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / sqlalchemy-trino-0.5.0.tar.gz

Download URL sqlalchemy-trino-0.5.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
716c9c9fe60ef6dfd3b0c75e300c054ab84bdc90f2d9789247f8f4bd816814fe
BLAKE2b-256 checksum
How to use checksums
4c95926fef6ea988ea5707ffafd0ccdbe1798668c4e5ba253d4c7b8f9a37a959
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release files / sqlalchemy_trino-0.5.0-py3.9.egg

Download URL sqlalchemy_trino-0.5.0-py3.9.egg
Size 2.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
c0ed0b28aeced7d7ffaf526d8d018ebd25f65bab41ddee6cad7f5825f56fd6e3
BLAKE2b-256 checksum
How to use checksums
ad019b3a2318d3906765794e173de151c89ca145b692a1244bdbbd3fb2db1c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release files / sqlalchemy_trino-0.5.0-py3-none-any.whl

Download URL sqlalchemy_trino-0.5.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06e54562f5d326592b8254449686215a8e38e46b8c1d5534169271ce143f61af
BLAKE2b-256 checksum
How to use checksums
0dfb0ae57e8f2ddb803e5cc39c5266cd619cf9dd6e03868d469e83b197e9d65d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.5.0 This release

3 release files

0.4.1

3 release files

0.4.0

3 release files

0.3.0

3 release files

0.2.2

3 release files

0.2.0

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page