Presto Python Client

Python DB-API client for Presto
Alternatives To Presto Python Client
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Presto Python Client2242353 months ago14September 07, 202344apache-2.0Python
Python DB-API client for Presto
Presto Admin152
4 years ago56apache-2.0Python
A tool to install, configure and manage Presto installations
Presto Testo37
6 years ago1otherHTML
Opera's Presto test suite as it applies to W3C specifications
Presto Companion App14
5 years agoDart
A companion app for Presto - Toronto's transit payment cards.
Docker Presto8
8 years agoShell
Facebook Presto docker image for development and testing purposes.
Presto Checks3
6 years ago5apache-2.0Shell
Additional tests for Presto. As opposed to tests ran on every commit, those tests are run on a fixed schedule.
Package Presto Query Builder Php2
5 years agomitPHP
Building presto query
Alternatives To Presto Python Client
Select To Compare

Alternative Project Comparisons

Build Status


This package provides a client interface to query Presto a distributed SQL engine. It supports Python 2.7, 3.5, 3.6, 3.7, and pypy.


$ pip install presto-python-client

Quick Start

Use the DBAPI interface to query Presto:

import prestodb
cur = conn.cursor()
cur.execute('SELECT * FROM system.runtime.nodes')
rows = cur.fetchall()

This will query the system.runtime.nodes system tables that shows the nodes in the Presto cluster.

The DBAPI implementation in prestodb.dbapi provides methods to retrieve fewer rows for example Cursorfetchone() or Cursor.fetchmany(). By default Cursor.fetchmany() fetches one row. Please set prestodb.dbapi.Cursor.arraysize accordingly.

Basic Authentication

The BasicAuthentication class can be used to connect to a LDAP-configured Presto cluster:

import prestodb
    host='coordinator url',
    auth=prestodb.auth.BasicAuthentication("principal id", "password"),
cur = conn.cursor()
cur.execute('SELECT * FROM system.runtime.nodes')
rows = cur.fetchall()

Oauth Authentication

To enable GCS access, Oauth authentication support is added by passing in a shadow.json file of a service account. Following example shows a use case where both Kerberos and Oauth authentication are enabled.

import getpass
import prestodb
from prestodb.client import ClientSession, PrestoRequest, PrestoQuery
from requests_kerberos import DISABLED

kerberos_auth = prestodb.auth.KerberosAuthentication(
   service_name='kerberos service name',

req = PrestoRequest(
    host='GCP coordinator url',
    service_account_file='Service account json file path',

query = PrestoQuery(req, "SELECT * FROM system.runtime.nodes")
rows = list(query.execute())


The client runs by default in autocommit mode. To enable transactions, set isolation_level to a value different than IsolationLevel.AUTOCOMMIT:

import prestodb
from prestodb import transaction
with prestodb.dbapi.connect(
) as conn:
  cur = conn.cursor()
  cur.execute('INSERT INTO sometable VALUES (1, 2, 3)')
  cur.execute('INSERT INTO sometable VALUES (4, 5, 6)')

The transaction is created when the first SQL statement is executed. prestodb.dbapi.Connection.commit() will be automatically called when the code exits the with context and the queries succeed, otherwise `prestodb.dbapi.Connection.rollback()' will be called.

Running Tests

There is a helper scripts, run, that provides commands to run tests. Type ./run tests to run both unit and integration tests.

presto-python-client uses pytest for its tests. To run only unit tests, type:

$ pytest tests

Then you can pass options like --pdb or anything supported by pytest --help.

To run the tests with different versions of Python in managed virtualenvs, use tox (see the configuration in tox.ini):

$ tox

To run integration tests, make sure the Docker daemon is running and then run:

$ pytest integration_tests

They build a Docker image and then run a container with a Presto server:

  • the image is named presto-server:${PRESTO_VERSION}
  • the container is named presto-python-client-tests-{uuid4()[:7]}

The container is expected to be removed after the tests are finished.

Please refer to the Dockerfile for details. You will find the configuration in etc/.

You can use ./run to manipulate the containers:

  • ./run presto_server: build and run Presto in a container
  • ./run presto_cli CONTAINER_ID: connect the Java Presto CLI to a container
  • ./run list: list the running containers
  • ./run clean: kill the containers


Start by forking the repository and then modify the code in your fork. Please refer to before submitting your contributions.

Clone the repository and go inside the code directory. Then you can get the version with python --version.

We recommend that you use virtualenv to develop on presto-python-client:

$ virtualenv /path/to/env
$ /path/to/env/bin/activate
$ pip install -r requirements.txt

For development purpose, pip can reference the code you are modifying in a virtualenv:

$ pip install -e .[tests]

That way, you do not need to run pip install again to make your changes applied to the virtualenv.

When the code is ready, submit a Pull Request.

Need Help?

Feel free to create an issue as it make your request visible to other users and contributors.

If an interactive discussion would be better or if you just want to hangout and chat about the Presto Python client, you can join us on the #presto-python-client channel on Slack.

Popular Presto Projects
Popular Testing Projects
Popular Data Processing Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Api Client