Registry / database / hive-metastore-client

hive-metastore-client

JSON →
library1.0.9pypypi✓ verified 85d ago

The `hive-metastore-client` library provides a Pythonic interface for connecting to and performing Data Definition Language (DDL) operations on a Hive Metastore using the Thrift protocol. It simplifies interactions with Hive metadata, enabling users to programmatically create and manage databases, tables, and partitions. Actively maintained by QuintoAndar, the library is currently at version 1.0.9, offering a high-level abstraction over the underlying Thrift APIs.

pip install hive-metastore-client
INSTALL
IMPORT
SIG · HIVE-METASTORE-CLI
H
hive-metastore-client
databasepythonv1.0.9
Install
3.3s avg
Import
470ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.9 · 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
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.478s · 24.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.3s · import 0.461s · 25MB
23MB installed
● package 23MB
Code
Verified usage

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

HiveMetastoreClient
from hive_metastore_client import HiveMetastoreClient
DatabaseBuilder
from hive_metastore_client.builders import DatabaseBuilder
TableBuilder
from hive_metastore_client.builders import TableBuilder

This quickstart demonstrates how to instantiate the HiveMetastoreClient, create a new database, and then create a table within that database. It uses the provided builders for constructing Thrift objects and includes basic error handling for connection issues. Ensure the Hive Metastore service is running and accessible at the specified host and port (defaults to localhost:9083, configurable via environment variables).

import os from hive_metastore_client import HiveMetastoreClient from hive_metastore_client.builders import DatabaseBuilder, FieldSchemaBuilder, TableBuilder from hive_metastore_client.thrift_files.libraries.thrift_hive_metastore_client.ttypes import Table, FieldSchema, StorageDescriptor, SerDeInfo HIVE_HOST = os.environ.get('HIVE_METASTORE_HOST', 'localhost') HIVE_PORT = int(os.environ.get('HIVE_METASTORE_PORT', '9083')) try: # 1. Create a database db_name = "my_test_database" database = DatabaseBuilder(name=db_name).build() with HiveMetastoreClient(HIVE_HOST, HIVE_PORT) as hive_client: hive_client.create_database(database, if_not_exists=True) print(f"Database '{db_name}' created successfully (or already exists).") # 2. Create a table in the new database table_name = "my_test_table" columns = [ FieldSchemaBuilder(name="id", type="int").build(), FieldSchemaBuilder(name="name", type="string").build() ] table = TableBuilder(name=table_name, database_name=db_name, columns=columns).build() hive_client.create_table(table, if_not_exists=True) print(f"Table '{db_name}.{table_name}' created successfully (or already exists).") # Example: Get the created table retrieved_table = hive_client.get_table(db_name, table_name) print(f"Retrieved table: {retrieved_table.name} in database {retrieved_table.dbName}") except Exception as e: print(f"An error occurred: {e}") print("Ensure HIVE_METASTORE_HOST and HIVE_METASTORE_PORT environment variables are set or defaults are correct.") print("Also, verify that the Hive Metastore service is running and accessible.")
Debug
Known issues
gotchaThe client relies on the Thrift protocol. If you attempt to manually compile or regenerate Thrift files (an advanced use case), ensure you use a compatible `thrift` compiler version. The project documentation noted using Thrift 0.14.0 for internal generation. Incompatibilities can lead to cryptic errors if the generated Python code is not consistent with the Metastore server's Thrift definition.
fix
For most users, this library provides pre-generated Thrift interfaces, so manual compilation is not required. If necessary, refer to the library's `thrift_files` directory and documentation for guidance on specific Thrift compiler versions and generation steps.
affects: All versions
gotchaDirect connection failures often stem from incorrect Hive Metastore host or port configurations. The `HiveMetastoreClient` requires precise network location of the Metastore service.
fix
Double-check `HIVE_HOST` and `HIVE_PORT` (or equivalent configuration) values. Ensure the Hive Metastore service is actively running and is reachable from where the Python client is executed. Network firewalls or incorrect DNS resolution can also prevent connections.
affects: All versions
gotchaCompatibility with the underlying Hive Metastore server version is crucial. While `hive-metastore-client` aims to abstract complexities, major version differences in Hive (e.g., Hive 2.x vs 3.x vs 4.x) can introduce breaking changes in the Metastore's Thrift API. Such changes might affect functionality or lead to unexpected behavior if the client's internal Thrift definitions do not align with the server.
fix
Consult the `hive-metastore-client` GitHub issues or documentation for known compatibility limitations with specific Hive Metastore versions. It's generally recommended to test thoroughly when upgrading either the client library or the Hive Metastore server.
affects: All versions
Errors
Common errors & fixes
TTransportException: Could not connect to <HIVE_HOST>:<HIVE_PORT>
The Python client failed to establish a network connection to the specified Hive Metastore host and port. This is often due to the Metastore service not running, incorrect host/port, or network/firewall issues.
fix
Verify that the Hive Metastore service is running. Check that the `HIVE_METASTORE_HOST` and `HIVE_METASTORE_PORT` (or equivalent) configured in your client code precisely match the running Metastore service. Use network tools (like `ping`, `telnet`, or `nc`) to confirm network reachability from the client machine to the Metastore server on the specified port.
Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
This error, typically seen in the Hive Metastore server logs or indirectly reported, indicates a fundamental issue within the Metastore's ability to initialize its internal client, often due to configuration problems, database connectivity, or resource exhaustion (e.g., too many connections to its backend database).
fix
This usually points to an issue on the Hive Metastore server side, not directly the Python client. Check the Hive Metastore server logs for more detailed errors. Common fixes include verifying the `hive-site.xml` configuration (especially `hive.metastore.uris` and database connection details), ensuring the Metastore's backend database is accessible and not overloaded, and restarting the Metastore service.
Upgrade
Version history
1.0.9latest on PyPI · released Aug 23, 2021
Audit
Dependencies
thriftoptionalThe library internally relies on Thrift for protocol communication. While the client ships with pre-generated Thrift Python libraries, users who need to regenerate Thrift files or interact at a lower level may require the `thrift` package and compiler.
Agent activity
6 hits · last 30 days
node
6
Resources