Presto Client (Renamed to Trino Python Client)
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
-
ModuleNotFoundError: No module named 'presto'
cause You have installed the new `trino` package but your code is still trying to import from the old `presto` package name.fixChange all import statements in your code from `import presto` or `from presto...` to `import trino` or `from trino...`. -
ModuleNotFoundError: No module named 'trino-python-client'
cause You are trying to import the Python package using its PyPI project name (`trino-python-client`), which contains a hyphen and is not the correct importable package name.fixThe correct package to import is `trino`. Change your import statement to `import trino` (after ensuring you've installed it with `pip install trino`). -
trino.exceptions.TrinoQueryError: Server error: io.trino.spi.security.AccessDeniedException: Cannot select from table system.runtime.nodes
cause The Trino server denied the query, usually because the connected user lacks necessary permissions or the specified catalog/schema is incorrect or inaccessible.fixVerify the `user`, `catalog`, and `schema` parameters in your `trino.dbapi.connect` call. Ensure the user specified has the required privileges to access the queried table/schema on the Trino cluster. -
requests.exceptions.SSLError: HTTPSConnectionPool(...) Max retries exceeded with url: /v1/statement
cause The client failed to establish a secure (HTTPS) connection to the Trino server. This can be due to `http_scheme` not being set to `'https'`, an untrusted server certificate, or an incorrect certificate path.fixIf your Trino server uses HTTPS, ensure `http_scheme='https'` in your connection parameters. If you are using self-signed certificates, you may need to provide the certificate path via the `cert` parameter or (less securely) set `verify=False`.
Warnings
- breaking The `presto-client` library has been officially renamed and superseded by the `trino` package. Continuing to use `presto-client` is not recommended due to lack of updates and potential incompatibilities with newer Trino servers.
- gotcha The PyPI project `trino-python-client` (which is the successor to `presto-client`) is installed using the package name `trino` (`pip install trino`), and imported as `import trino`. Attempting to install or import using `trino-python-client` directly will fail.
- gotcha Connecting to a Trino server over HTTPS (SSL/TLS) requires explicit configuration for `http_scheme` and potentially certificate verification.
- gotcha Performance for fetching large query results can be significantly improved by installing optional compression libraries, `lz4` or `zstd`.
Install
-
pip install trino
Imports
- connect
from presto.dbapi import connect
from trino.dbapi import connect
- TrinoQueryError
from presto.exceptions import PrestoQueryError
from trino.exceptions import TrinoQueryError
Quickstart
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)