Registry / database / pure-transport

pure-transport

JSON →
library0.2.0pypypi✓ verified 86d ago

pure-transport is a Python library providing a SASL-based Thrift transport layer specifically designed for PyHive. It aims to offer better compatibility with newer versions of the `thrift` library (0.11.0+) than the `thrift_sasl` library, addressing common issues encountered when connecting to Hive or Impala servers requiring SASL authentication. The current version is 0.2.0, and it is released on an as-needed basis to support PyHive ecosystems.

pip install pure-transport
INSTALL
IMPORT
SIG · PURE-TRANSPORT
P
pure-transport
databasepythonv0.2.0
Install
4.6s avg
Import
—
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.2.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
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.3MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 4.6s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

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

factory
✓ from puretransport import factory
✗ from pure_transport.sasl_transport import TSaslClientTransport
transport_factory
✓ from puretransport import transport_factory
✗ from pure_transport.sasl_transport import TSaslClientTransport

This quickstart demonstrates how to initialize `pure_transport.sasl_transport.TSaslClientTransport` using `thrift` components. This transport object can then be passed to higher-level clients like PyHive or Impala-dbapi. The example uses environment variables for configuration for easy testing; replace them with your actual connection details.

import os from thrift.transport.TSocket import TSocket from thrift.transport.TTransport import TBufferedTransport from thrift.protocol import TBinaryProtocol from pure_transport.sasl_transport import TSaslClientTransport # 1. Define connection details (replace with your actual server info) # Using os.environ.get for runnable example, set environment variables or replace directly HIVE_HOST = os.environ.get("HIVE_HOST", "localhost") HIVE_PORT = int(os.environ.get("HIVE_PORT", "10000")) SASL_MECHANISM = os.environ.get("HIVE_SASL_MECHANISM", "PLAIN") # e.g., PLAIN, GSSAPI SASL_USERNAME = os.environ.get("HIVE_SASL_USERNAME", "testuser") SASL_PASSWORD = os.environ.get("HIVE_SASL_PASSWORD", "testpass") # Only for PLAIN auth_params = { "mechanism": SASL_MECHANISM, "username": SASL_USERNAME, } if SASL_MECHANISM == "PLAIN": auth_params["password"] = SASL_PASSWORD elif SASL_MECHANISM == "GSSAPI": auth_params["service_name"] = os.environ.get("HIVE_SERVICE_NAME", "hive") # Add other GSSAPI parameters if necessary, e.g., principal, keytab print(f"Attempting to initialize transport for {HIVE_HOST}:{HIVE_PORT} with SASL {SASL_MECHANISM}...") try: # 2. Create a TSocket (from thrift) # In a real PyHive/Impala-dbapi scenario, this is often handled internally. socket = TSocket(HIVE_HOST, HIVE_PORT) # 3. Create the pure_transport SASL transport, wrapping the TSocket # This is the core component provided by pure-transport transport = TSaslClientTransport( socket, HIVE_HOST, # Host for SASL negotiation (e.g., Kerberos principal resolution) **auth_params ) # 4. Wrap with a buffered transport (optional but common for performance) buffered_transport = TBufferedTransport(transport) # 5. Create a Thrift protocol protocol = TBinaryProtocol.TBinaryProtocol(buffered_transport) print(f"\nSuccessfully initialized pure_transport TSaslClientTransport for {HIVE_HOST}:{HIVE_PORT}") print(f"SASL Mechanism: {SASL_MECHANISM}") print(f"Transport object type: {type(transport).__name__}") print("This transport and protocol can now be used with a Thrift client (e.g., PyHive).") # In a full application, you would then open the transport and use a Thrift client: # buffered_transport.open() # client = MyThriftClient(protocol) # result = client.some_method() # buffered_transport.close() except Exception as e: print(f"\nFailed to initialize transport: {e}") print("Ensure `pure-transport`, `thrift`, and `thrift_sasl` are installed.") print("For actual connection, verify network and server availability.")
Debug
Known issues
breakingUsing `thrift_sasl.TSaslClientTransport` with `thrift` library versions 0.11.0 or higher can lead to connection errors or unexpected behavior due to API changes in `thrift`. `pure-transport` was developed specifically to address this incompatibility.
fix
Replace `from thrift_sasl import TSaslClientTransport` with `from pure_transport.sasl_transport import TSaslClientTransport`. Ensure `pure-transport` is installed.
affects: thrift>=0.11.0 when used with thrift_sasl (any version)
gotchaConnection failures due to misconfigured SASL mechanism (e.g., `PLAIN`, `GSSAPI`) or incorrect authentication parameters (username, password, service principal name).
fix
Verify the SASL mechanism and required authentication parameters against your Hive/Impala server configuration. For GSSAPI, ensure Kerberos setup is correct and `service_name` matches the server's principal.
affects: All versions
gotchaAlthough `pure-transport` replaces `thrift_sasl.TSaslClientTransport` for compatibility, it still depends on the `thrift_sasl` library for its underlying SASL negotiation logic. If `thrift_sasl` is not installed, `pure-transport` will fail to initialize or perform SASL negotiation.
fix
Ensure `thrift_sasl` is installed in your environment: `pip install thrift_sasl`.
affects: All versions
Upgrade
Version history
0.2.0latest on PyPI · released Jan 29, 2020
Audit
Dependencies
thriftrequiredRequired for underlying Thrift protocol and transport structures.
thrift_saslrequiredProvides the core SASL negotiation logic.
Agent activity
20 hits · last 30 days
node
16
Resources
pure-transport — pip install pure-transport · libregistry