{"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pure-transport"],"cli":null},"imports":["from pure_transport.sasl_transport import TSaslClientTransport"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}