{"id":10071,"library":"pure-transport","title":"Pure Transport for PyHive","description":"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.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/devinstevenson/pure-transport","tags":["thrift","sasl","pyhive","database","transport","hive","impala"],"install":[{"cmd":"pip install pure-transport","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for underlying Thrift protocol and transport structures.","package":"thrift","optional":false},{"reason":"Provides the core SASL negotiation logic.","package":"thrift_sasl","optional":false}],"imports":[{"note":"pure-transport provides a compatible TSaslClientTransport when thrift_sasl is incompatible with modern `thrift` versions (0.11.0+). Use this as a direct replacement.","wrong":"from thrift_sasl import TSaslClientTransport","symbol":"TSaslClientTransport","correct":"from pure_transport.sasl_transport import TSaslClientTransport"}],"quickstart":{"code":"import os\nfrom thrift.transport.TSocket import TSocket\nfrom thrift.transport.TTransport import TBufferedTransport\nfrom thrift.protocol import TBinaryProtocol\nfrom pure_transport.sasl_transport import TSaslClientTransport\n\n# 1. Define connection details (replace with your actual server info)\n# Using os.environ.get for runnable example, set environment variables or replace directly\nHIVE_HOST = os.environ.get(\"HIVE_HOST\", \"localhost\")\nHIVE_PORT = int(os.environ.get(\"HIVE_PORT\", \"10000\"))\nSASL_MECHANISM = os.environ.get(\"HIVE_SASL_MECHANISM\", \"PLAIN\") # e.g., PLAIN, GSSAPI\nSASL_USERNAME = os.environ.get(\"HIVE_SASL_USERNAME\", \"testuser\")\nSASL_PASSWORD = os.environ.get(\"HIVE_SASL_PASSWORD\", \"testpass\") # Only for PLAIN\n\nauth_params = {\n    \"mechanism\": SASL_MECHANISM,\n    \"username\": SASL_USERNAME,\n}\nif SASL_MECHANISM == \"PLAIN\":\n    auth_params[\"password\"] = SASL_PASSWORD\nelif SASL_MECHANISM == \"GSSAPI\":\n    auth_params[\"service_name\"] = os.environ.get(\"HIVE_SERVICE_NAME\", \"hive\")\n    # Add other GSSAPI parameters if necessary, e.g., principal, keytab\n\nprint(f\"Attempting to initialize transport for {HIVE_HOST}:{HIVE_PORT} with SASL {SASL_MECHANISM}...\")\ntry:\n    # 2. Create a TSocket (from thrift)\n    # In a real PyHive/Impala-dbapi scenario, this is often handled internally.\n    socket = TSocket(HIVE_HOST, HIVE_PORT)\n\n    # 3. Create the pure_transport SASL transport, wrapping the TSocket\n    # This is the core component provided by pure-transport\n    transport = TSaslClientTransport(\n        socket,\n        HIVE_HOST, # Host for SASL negotiation (e.g., Kerberos principal resolution)\n        **auth_params\n    )\n\n    # 4. Wrap with a buffered transport (optional but common for performance)\n    buffered_transport = TBufferedTransport(transport)\n\n    # 5. Create a Thrift protocol\n    protocol = TBinaryProtocol.TBinaryProtocol(buffered_transport)\n\n    print(f\"\\nSuccessfully initialized pure_transport TSaslClientTransport for {HIVE_HOST}:{HIVE_PORT}\")\n    print(f\"SASL Mechanism: {SASL_MECHANISM}\")\n    print(f\"Transport object type: {type(transport).__name__}\")\n    print(\"This transport and protocol can now be used with a Thrift client (e.g., PyHive).\")\n\n    # In a full application, you would then open the transport and use a Thrift client:\n    # buffered_transport.open()\n    # client = MyThriftClient(protocol)\n    # result = client.some_method()\n    # buffered_transport.close()\n\nexcept Exception as e:\n    print(f\"\\nFailed to initialize transport: {e}\")\n    print(\"Ensure `pure-transport`, `thrift`, and `thrift_sasl` are installed.\")\n    print(\"For actual connection, verify network and server availability.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Replace `from thrift_sasl import TSaslClientTransport` with `from pure_transport.sasl_transport import TSaslClientTransport`. Ensure `pure-transport` is installed.","message":"Using `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.","severity":"breaking","affected_versions":"thrift>=0.11.0 when used with thrift_sasl (any version)"},{"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.","message":"Connection failures due to misconfigured SASL mechanism (e.g., `PLAIN`, `GSSAPI`) or incorrect authentication parameters (username, password, service principal name).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `thrift_sasl` is installed in your environment: `pip install thrift_sasl`.","message":"Although `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Use `from pure_transport.sasl_transport import TSaslClientTransport` instead of `from thrift_sasl import TSaslClientTransport`. Also ensure `pure-transport` is installed via `pip install pure-transport`.","cause":"This error often occurs when `thrift_sasl` is incompatible with the installed `thrift` version (0.11.0 or newer).","error":"ImportError: cannot import name 'TSaslClientTransport' from 'thrift_sasl'"},{"fix":"Check network connectivity to the Hive/Impala server (host, port). Verify the server is running. Ensure SASL authentication parameters (mechanism, username, password, service_name) are correct and match the target server's configuration.","cause":"The underlying `TSocket` failed to establish a connection to the specified host/port, or the connection was immediately rejected by the server, often due to authentication failure or the server not running.","error":"TTransportException: Could not connect to ..."},{"fix":"Correct the import path to `from pure_transport.sasl_transport import TSaslClientTransport`.","cause":"Attempting to import `TSaslClientTransport` directly from the top-level `pure_transport` module instead of its specific submodule.","error":"AttributeError: module 'pure_transport' has no attribute 'TSaslClientTransport'"}]}