Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
build_error
glibcpy 3.10–3.910 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
connect
✓ import pyhs2
conn = pyhs2.connect(...)
✗ from pyhs2.connections import connect
The primary connection function is directly available under the top-level 'pyhs2' module.
Pyhs2Exception
✓ from pyhs2.error import Pyhs2Exception
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}")
Debug
Known issues
breaking`pyhs2` does NOT support Python 3.x. It is designed for Python 2.x, and attempts to use it with Python 3.x will result in `ModuleNotFoundError` or other incompatibilities due to underlying dependencies like `sasl` and `cStringIO`.fixUse Python 2.x for `pyhs2` projects, or migrate to a maintained Python 3.x compatible alternative like `PyHive` or `impyla`.
affects: All versions (0.1.0 - 0.6.0) when used with Python 3.x
deprecatedThe `pyhs2` library is no longer maintained. The last release was in 2014, and the developer officially stated that maintenance ceased in January 2016, recommending alternatives.fixConsider migrating to actively maintained libraries such as `PyHive` (from Dropbox) or `impyla` (from Cloudera) for connecting to Hive Server 2.
affects: All versions (0.1.0 - 0.6.0)
gotchaInstalling `pyhs2` often fails due to missing system-level development headers for `cyrus-sasl`. The `sasl` Python package, a dependency, requires these headers to compile.fixBefore `pip install pyhs2`, install the necessary system packages: `sudo yum install cyrus-sasl-devel` on Red Hat/CentOS/Fedora systems, or `sudo apt-get update && sudo apt-get install libsasl2-dev` on Debian/Ubuntu systems.
affects: All versions
gotchaConnection issues (`TTransport.TTransportException: Could not connect`) are frequently caused by incorrect host, port, authentication mechanism, user, or password. Hive Server 2 typically runs on port 10000.fixVerify the Hive Server 2 hostname/IP, port (commonly 10000), and the correct authentication mechanism (e.g., `PLAIN` for simple username/password, or `KERBEROS` if configured). Check `hive-site.xml` for correct HiveServer2 configuration.
affects: All versions
gotchaFetching large result sets can appear to hang or be inefficient. The `fetchone()` and `hasMoreRows` pattern is recommended over simply iterating `cur.fetch()` for better control.fixInstead of `for i in cur.fetch():`, use a loop with `while cur.hasMoreRows: print cur.fetchone()`. Consider adding `LIMIT` clauses to queries during development.
affects: All versions
Upgrade
Version history
0.6.0latest on PyPI · released Nov 20, 2014
Audit
Dependencies
saslrequiredRequired for SASL authentication mechanisms. This dependency needs system-level SASL development headers for compilation.
thriftrequiredUnderpins the communication protocol with Hive Server 2.