Python Hive Server 2 Client Driver

0.6.0 · abandoned · verified Thu Apr 16

pyHS2 is a Python client driver designed for connecting to Hive Server 2. The project's last stable release was 0.6.0 in November 2014. It is no longer actively maintained, with the developer ceasing support in early 2016 and recommending alternative libraries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to Hive Server 2 using `pyhs2`, execute a sample query, retrieve schema information, and fetch results. It uses environment variables for connection parameters for flexibility. Ensure your Hive Server 2 is running and accessible.

import os
import pyhs2

hive_host = os.environ.get('HIVE_HOST', 'localhost')
hive_port = int(os.environ.get('HIVE_PORT', '10000'))
hive_user = os.environ.get('HIVE_USER', 'hive')
hive_password = os.environ.get('HIVE_PASSWORD', '')
hive_database = os.environ.get('HIVE_DATABASE', 'default')

try:
    with pyhs2.connect(
        host=hive_host,
        port=hive_port,
        authMechanism="PLAIN", # or "KERBEROS" or None
        user=hive_user,
        password=hive_password,
        database=hive_database
    ) as conn:
        print("Successfully connected to Hive Server 2.")
        with conn.cursor() as cur:
            # Show databases
            print(f"Databases: {cur.getDatabases()}")

            # Execute a query
            cur.execute("SELECT * FROM some_table LIMIT 5")

            # Return column info
            print(f"Schema: {cur.getSchema()}")

            # Fetch table results
            print("Query Results:")
            for row in cur.fetch():
                print(row)

except pyhs2.error.Pyhs2Exception as e:
    print(f"pyhs2 error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →