Asyncio client for the Trino distributed SQL Engine
pip install aiotrinoIntroduction
This package provides a asyncio client interface to query Trino a distributed SQL engine. It supports Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.
Installation
$ pip install aiotrino
Quick Start
Use the DBAPI interface to query Trino:
import aiotrino
conn = aiotrino.dbapi.connect(
host='localhost',
port=8080,
user='the-user',
catalog='the-catalog',
schema='the-schema',
)
cur = await conn.cursor()
await cur.execute('SELECT * FROM system.runtime.nodes')
rows = await cur.fetchall()
await conn.close()
Or with context manager
import aiotrino
async with aiotrino.dbapi.connect(
host='localhost',
port=8080,
user='the-user',
catalog='the-catalog',
schema='the-schema',
) as conn:
cur = await conn.cursor()
await cur.execute('SELECT * FROM system.runtime.nodes')
rows = await cur.fetchall()
This will query the system.runtime.nodes system tables that shows the nodes
in the Trino cluster.
The DBAPI implementation in aiotrino.dbapi provides methods to retrieve fewer
rows for example Cursorfetchone() or Cursor.fetchmany(). By default
Cursor.fetchmany() fetches one row. Please set
trino.dbapi.Cursor.arraysize accordingly.
For backwards compatibility with PrestoSQL, override the headers at the start of your application
import aiotrino
aiotrino.constants.HEADERS = aiotrino.constants.PrestoHeaders
Basic Authentication
The BasicAuthentication class can be used to connect to a LDAP-configured Trino
cluster:
import aiotrino
conn = aiotrino.dbapi.connect(
host='coordinator url',
port=8443,
user='the-user',
catalog='the-catalog',
schema='the-schema',
http_scheme='https',
auth=aiotrino.auth.BasicAuthentication("principal id", "password"),
)
cur = await conn.cursor()
await cur.execute('SELECT * FROM system.runtime.nodes')
rows = await cur.fetchall()
await conn.close()