Registry / database / pyhive

pyhive

JSON →
library0.7.0pypypi✓ verified 27d ago

PyHive provides Python DB-API and SQLAlchemy interfaces for various data warehouses, primarily Apache Hive and Presto. It enables Python applications to connect, query, and fetch results from these systems. The current version is 0.7.0, with a release cadence that is somewhat sporadic, with significant gaps between major and minor releases.

pip install pyhive[hive]
INSTALL
IMPORT
SIG · PYHIVE
P
pyhive
databasepythonv0.7.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
1/3 runs
1/3 runs
py 3.11
1/3 runs
1/3 runs
py 3.12
1/3 runs
1/3 runs
py 3.13
1/3 runs
1/3 runs
py 3.9
1/3 runs
1/3 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connect
from pyhive.hive import connect
connect
from pyhive.presto import connect
HiveConnection
from pyhive.hive import Connection as HiveConnection
PrestoConnection
from pyhive.presto import Connection as PrestoConnection

This quickstart demonstrates how to establish a connection to Apache Hive using `pyhive.hive`, execute a simple query, and fetch results. It uses environment variables for connection details for security and flexibility. Remember to install `pyhive[hive]` to get the necessary dependencies. For Presto, replace `pyhive.hive` with `pyhive.presto` and adjust connection parameters.

import os from pyhive import hive # Example for Hive connection # Ensure HiveServer2 is running and accessible # Replace with your actual host, port, username, database host = os.environ.get('HIVE_HOST', 'localhost') port = int(os.environ.get('HIVE_PORT', 10000)) username = os.environ.get('HIVE_USERNAME', 'anonymous') database = os.environ.get('HIVE_DATABASE', 'default') connection = None cursor = None try: connection = hive.connect(host=host, port=port, username=username, database=database) cursor = connection.cursor() # Execute a query cursor.execute('SELECT 1 + 1') # Fetch results result = cursor.fetchone() print(f"Query result: {result}") cursor.execute('SHOW TABLES') tables = cursor.fetchall() print("Available tables:") for table in tables: print(f" {table[0]}") except Exception as e: print(f"An error occurred: {e}") finally: if cursor: cursor.close() if connection: connection.close()
Debug
Known issues
breakingMajor protocol and Thrift binding updates in PyHive versions can cause incompatibility with older HiveServer2 versions. Specifically, v0.2.0 changed to Hive protocol V6 (requiring Hive 0.13+), and v0.5.0 updated Thrift bindings to V11. Ensure your PyHive version matches the expected protocol/Thrift version of your HiveServer2.
fix
Check the release notes for your PyHive version for required HiveServer2 versions or Thrift binding compatibility. Upgrade HiveServer2 or downgrade PyHive as necessary to match protocols.
affects: 0.2.0, 0.5.0, 0.7.0 (and potentially others)
breakingPyHive v0.2.0 introduced changes to data return types: rows are now returned as tuples instead of lists, and binary data is returned as byte strings instead of Unicode strings. This can break existing code that assumes specific data types.
fix
Update your code to expect tuples for rows and byte strings for binary data when upgrading from PyHive versions prior to 0.2.0.
affects: 0.2.0 and newer
gotchaPyHive's core installation (`pip install pyhive`) does not include necessary dependencies for Hive, Presto, Kerberos, or SQLAlchemy integration. These must be installed via optional extras.
fix
Always install PyHive with the required extras, e.g., `pip install pyhive[hive]`, `pip install pyhive[presto,hive_kerberos,sqlalchemy]` for full functionality.
affects: All versions
gotchaOlder PyHive versions explicitly dropped support for specific SQLAlchemy versions (e.g., v0.5.0 dropped SQLAlchemy 0.6, v0.5.1 dropped SQLAlchemy 0.7). While newer PyHive versions generally aim for compatibility, always check if you're using an older PyHive with a very old or very new SQLAlchemy version.
fix
For SQLAlchemy integration, use a recent version of PyHive and a reasonably modern and compatible version of SQLAlchemy (typically the latest stable versions work best).
affects: 0.5.0, 0.5.1, and potentially others
Upgrade
Version history
0.7.0latest on PyPI · released Aug 17, 2023
Audit
Dependencies
thriftoptionalRequired for Hive connectivity. Specific versions of PyHive may mandate specific Thrift versions.
sasloptionalRequired for Hive Kerberos authentication (`pyhive[hive_kerberos]` extra).
requestsoptionalRequired for Presto connectivity (`pyhive[presto]` extra).
sqlalchemyoptionalRequired for SQLAlchemy integration (`pyhive[sqlalchemy]` extra).
Agent activity
11 hits · last 30 days
node
10
Resources
pyhive — pip install pyhive · libregistry