Presto Client (Renamed to Trino Python Client)

0.303.0 · renamed · verified Thu Apr 16

The `presto-client` library, currently at version 0.303.0, has been renamed and superseded by the `trino-python-client` project, which is available on PyPI as the `trino` package. While `presto-client` exists, it is largely a stub advising migration. Trino (formerly PrestoSQL) is a distributed SQL query engine for big data analytics. The actively maintained `trino` library provides a DBAPI 2.0 compliant client, with current versions released frequently, often monthly or bi-monthly, reflecting active development and maintenance.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a Trino cluster, execute a simple query, and fetch results using the DBAPI 2.0 interface. It uses environment variables for configuration to avoid hardcoding sensitive information. The `with conn.cursor()` syntax is supported from version 0.334.0 onwards.

import trino
import os

# Connect to Trino using environment variables for host, port, etc.
# Default to common local settings if env vars are not set.
conn = trino.dbapi.connect(
    host=os.environ.get('TRINO_HOST', 'localhost'),
    port=int(os.environ.get('TRINO_PORT', '8080')),
    user=os.environ.get('TRINO_USER', 'python_client'),
    catalog=os.environ.get('TRINO_CATALOG', 'system'),
    schema=os.environ.get('TRINO_SCHEMA', 'runtime'),
    http_scheme=os.environ.get('TRINO_HTTP_SCHEME', 'http'),
    auth=trino.auth.BasicAuthentication(
        username=os.environ.get('TRINO_USERNAME', ''),
        password=os.environ.get('TRINO_PASSWORD', '')
    ) if os.environ.get('TRINO_USERNAME') else None,
)

with conn.cursor() as cur:
    cur.execute("SELECT node_id, uri FROM nodes LIMIT 5")
    for row in cur.fetchall():
        print(row)

view raw JSON →