Presto access is represented by many Python libraries among those are Dropbox/PyHive, prestosql/presto-python-client, prestodb/presto-python-client, and easydatawarehousing/prestoclient. Mostly of libraries use Python DB-API interface to access Presto which uniforms commands.
Python Access to Presto Cluster with PyHive article describes Dropbox/PyHive library usage.
prestosql/presto-python-client library is actively supported by Presto developers. The sample is run with Python 3 in Windows.
1. Install Presto client library
sudo pip3 install presto-client
Windows. Run as administrator.
pip install presto-client
2. Include requested libraries
3. Establish connection
Access to Presto cluster without password.
conn = presto.connect(host='localhost', port=8080, catalog='system', schema='runtime')
Presto cluster is secured by password but skip SSL verification. This case might be used during development stage.
conn = presto.connect(host='localhost', port=443, http_scheme='https', catalog='system', schema='runtime', auth=presto.auth.BasicAuthentication('<user name>', '<password>'), verify=False)
Presto cluster is secured by password.
Option #1. Follow instructions in Convert Java Keystore to PEM File Format article to create
presto.crtfile. The file contains Presto SSL public certificate converted from Java keystore file.
Option #2. Extract
presto.crtcertificate from Internet Browser. Follow Export TLS/SSL Server Certificate from Internet Browser article.
conn = presto.connect(host='localhost', port=443, http_scheme='https', catalog='system', schema='runtime', auth=presto.auth.BasicAuthentication('<user name>', '<password>'), verify='presto.crt')
4. Create cursor
cur = conn.cursor()
5. Retrieve data
cur.execute('SELECT * FROM nodes') for row in cur.fetchall(): print(row)
To disable insecure warnings during https requests if
verify=False, add the code in
import urllib3 urllib3.disable_warnings()
In case of getting
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) error, check your certificate expiration date. The date has to be valid.