Impyla

0.22.0 · active · verified Thu Apr 09

Impyla is a Python client for HiveServer2 implementations, such as the Impala distributed query engine. It provides a Python DB API 2.0 (PEP 249)-compliant interface, enabling Python applications to connect to Impala and execute SQL queries. The library, currently at version 0.22.0, is actively maintained by Cloudera with a regular, though somewhat irregular, release cadence, often including alpha and stable versions within a year.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to an Impala server, execute a simple SQL query, and fetch the results using the DB API 2.0 interface. It uses environment variables for host and port for flexibility.

import os
from impala.dbapi import connect

IMPALA_HOST = os.environ.get('IMPYLA_TEST_HOST', 'localhost')
IMPALA_PORT = int(os.environ.get('IMPYLA_TEST_PORT', 21050))

try:
    conn = connect(host=IMPALA_HOST, port=IMPALA_PORT)
    cursor = conn.cursor()
    cursor.execute('SHOW TABLES')
    tables = cursor.fetchall()
    print('Tables in Impala:')
    for table in tables:
        print(table[0])
    cursor.close()
    conn.close()
except Exception as e:
    print(f"Could not connect or query Impala: {e}")
    print("Please ensure an Impala daemon is running at the specified host and port.")

view raw JSON →