The `trino` Python client provides a client interface to query Trino, a distributed SQL engine for interactive and batch big data processing. It offers a low-level client, a DBAPI 2.0 implementation, and a SQLAlchemy adapter. The current version is 0.337.0 and releases are frequent, often several per month, incorporating fixes, features, and dependency updates.
pip install trinoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a Trino server using the DBAPI interface, execute a simple query, and fetch results. It uses environment variables for connection parameters for flexibility and basic authentication if a password is provided. The `with` statement ensures proper resource management for both connection and cursor.
Upgrade your Python environment to 3.9 or newer.
For optimal performance, explicitly `pip install orjson`. Review any custom JSON serialization/deserialization logic if unexpected behavior arises.
If using spooling with compression, ensure the necessary libraries are installed, e.g., `pip install trino[full]` or `pip install lz4 zstandard`.
Set `cursor.arraysize = N` (where `N` is your desired batch size) before calling `fetchmany()` to retrieve multiple rows at once, or use `fetchall()`.
Remove trailing semicolons from individual SQL statements when passing them to `cursor.execute()`, especially if concatenating multiple statements or running them one by one.
Always use `http_scheme='https'` and configure proper SSL/TLS verification in production environments. Only enable insecure channels with extreme caution and understanding of the security implications.
Install the necessary system-level Kerberos development libraries (e.g., `sudo apt-get install libkrb5-dev` on Debian/Ubuntu, `sudo yum install krb5-devel` on RHEL/CentOS, or similar for other operating systems) before attempting to `pip install trino[gssapi]`.
pip install trino
Verify that the Trino server is running, check network connectivity and firewall rules, and confirm the `host` and `port` parameters in your connection string.
pip install trino[sqlalchemy]
Provide the path to the trusted CA certificate using the `verify` parameter (e.g., `trino.dbapi.connect(..., verify='/path/to/ca.crt')`) or, for development/testing, set `verify=False` to disable SSL verification.