{"id":2198,"library":"presto-python-client","title":"Presto Python Client","description":"Client for the Presto distributed SQL Engine. It provides both a low-level client and a DBAPI 2.0 implementation. As of version 0.8.4, it officially supports Python 2.7, 3.5, 3.6, 3.7, and pypy, offering standard database connectivity for querying Presto clusters.","status":"active","version":"0.8.4","language":"en","source_language":"en","source_url":"https://github.com/prestodb/presto-python-client","tags":["database","presto","sql","dbapi"],"install":[{"cmd":"pip install presto-python-client","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for command-line utilities or internal components.","package":"click","optional":false},{"reason":"Used for IP address handling, likely for network communication.","package":"ipaddress","optional":false},{"reason":"Core library for HTTP communication with the Presto server.","package":"requests","optional":false},{"reason":"Python 2 and 3 compatibility utility.","package":"six","optional":false},{"reason":"Typing hints support (especially for Python 3.5+).","package":"typing","optional":false},{"reason":"Required for Kerberos authentication.","package":"requests-kerberos","optional":true},{"reason":"Required for OAuth authentication.","package":"google-auth","optional":true}],"imports":[{"note":"The primary function to establish a connection to Presto.","symbol":"connect","correct":"from prestodb.dbapi import connect"},{"note":"Used for authenticating with Presto using username and password.","symbol":"BasicAuthentication","correct":"from prestodb.auth import BasicAuthentication"},{"note":"Enum for setting transaction isolation levels.","symbol":"IsolationLevel","correct":"from prestodb.transaction import IsolationLevel"},{"note":"Specific exception for Presto query-related errors, inheriting from base Exception.","symbol":"PrestoQueryError","correct":"from prestodb.exceptions import PrestoQueryError"}],"quickstart":{"code":"import os\nfrom prestodb.dbapi import connect\nfrom prestodb.auth import BasicAuthentication\n\nhost = os.environ.get('PRESTO_HOST', 'localhost')\nport = int(os.environ.get('PRESTO_PORT', 8080))\nuser = os.environ.get('PRESTO_USER', 'the-user')\npassword = os.environ.get('PRESTO_PASSWORD', '') # Only if basic auth is needed\ncatalog = os.environ.get('PRESTO_CATALOG', 'the-catalog')\nschema = os.environ.get('PRESTO_SCHEMA', 'the-schema')\n\nauth = None\nif password:\n    auth = BasicAuthentication(user, password)\n\ntry:\n    conn = connect(\n        host=host,\n        port=port,\n        user=user,\n        catalog=catalog,\n        schema=schema,\n        http_scheme=os.environ.get('PRESTO_HTTP_SCHEME', 'http'),\n        auth=auth\n    )\n    cur = conn.cursor()\n\n    cur.execute('SELECT * FROM system.runtime.nodes')\n    rows = cur.fetchall()\n\n    print(\"Successfully connected to Presto and fetched data.\")\n    for row in rows:\n        print(row)\n\n    cur.close()\n    conn.close()\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to establish a connection to a Presto server using the DBAPI interface, execute a simple query, and fetch the results. It includes optional basic authentication and uses environment variables for configuration, making it suitable for secure execution in various environments."},"warnings":[{"fix":"Verify your Presto server type (PrestoDB vs. Trino) and install the corresponding client library (`presto-python-client` for PrestoDB, `trino` for Trino).","message":"Confusion with Trino/PrestoSQL Clients: Users often confuse `presto-python-client` (designed for PrestoDB) with clients for Trino (formerly PrestoSQL). Ensure you are installing and using `presto-python-client` if your backend is PrestoDB, and not `trino` or `presto-client` packages, which serve Trino clusters.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Develop and test your application against a compatible Python version, ideally within the officially supported range. Be prepared for potential compatibility issues if using newer Python interpreters.","message":"Older Python Version Support: As of version 0.8.4, the library officially supports Python 2.7, 3.5, 3.6, and 3.7. While it may function on newer Python versions (3.8+), these older versions are approaching or past their end-of-life and may not be actively tested or fully compatible with future changes.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Set `cursor.arraysize = <desired_batch_size>` before calling `cursor.fetchmany()` to retrieve more than one row at a time.","message":"`Cursor.fetchmany()` Default Behavior: By default, the `Cursor.fetchmany()` method retrieves only a single row. For efficient retrieval of multiple rows in batches, it is crucial to explicitly set `prestodb.dbapi.Cursor.arraysize` to the desired number of rows before calling `fetchmany()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When creating a connection, specify `isolation_level=IsolationLevel.READ_COMMITTED` (or another desired level) to enable transaction control.","message":"Autocommit Mode vs. Explicit Transactions: The client operates in autocommit mode by default. To enable explicit transaction management (e.g., `commit()` or `rollback()`), the `isolation_level` parameter in `prestodb.dbapi.connect()` must be set to a value other than `IsolationLevel.AUTOCOMMIT`, such as `IsolationLevel.READ_COMMITTED`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the `http_scheme` is set to 'https'. If using self-signed certificates, you may need to provide a `ca_bundle` path to the `auth` object or, for testing purposes only, disable verification by setting `conn._http_session.verify = False` (not recommended for production).","message":"SSL/TLS Certificate Verification Issues: When connecting to Presto via HTTPS, especially with self-signed certificates, `SSLCertVerificationError` is a common issue. This occurs if the client cannot verify the server's certificate.","severity":"gotcha","affected_versions":"All versions using HTTPS"},{"fix":"Verify network connectivity between client and server (e.g., using `ping` or `telnet`). Confirm the Presto server is running and accessible, and double-check the `host` and `port` parameters in your `connect()` call.","message":"Connection Timeouts and Refused Connections: Errors like `CONNECTION_TIMEOUT` or 'Connection Refused' typically indicate underlying network issues (firewalls, routing), an unresponsive or overloaded Presto server, or incorrect `host` and `port` configurations in the connection string.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}