title: How to Access Hive via Python?
body: <p><a href="https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python" rel="noreferrer">https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-Python</a> appears to be outdated.</p>
  
  <p>When I add this to /etc/profile:</p>
  
  <pre><code>export PYTHONPATH=$PYTHONPATH:/usr/lib/hive/lib/py
  </code></pre>
  
  <p>I can then do the imports as listed in the link, with the exception of <code>from hive import ThriftHive</code> which actually need to be:</p>
  
  <pre><code>from hive_service import ThriftHive
  </code></pre>
  
  <p>Next the port in the example was 10000, which when I tried caused the program to hang. The default Hive Thrift port is 9083, which stopped the hanging.</p>
  
  <p>So I set it up like so:</p>
  
  <pre><code>from thrift import Thrift
  from thrift.transport import TSocket
  from thrift.transport import TTransport
  from thrift.protocol import TBinaryProtocol
  try:
      transport = TSocket.TSocket('&lt;node-with-metastore&gt;', 9083)
      transport = TTransport.TBufferedTransport(transport)
      protocol = TBinaryProtocol.TBinaryProtocol(transport)
      client = ThriftHive.Client(protocol)
      transport.open()
      client.execute("CREATE TABLE test(c1 int)")
  
      transport.close()
  except Thrift.TException, tx:
      print '%s' % (tx.message)
  </code></pre>
  
  <p>I received the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/lib/hive/lib/py/hive_service/ThriftHive.py", line 68, in execute
  self.recv_execute()
  File "/usr/lib/hive/lib/py/hive_service/ThriftHive.py", line 84, in recv_execute
  raise x
  thrift.Thrift.TApplicationException: Invalid method name: 'execute'
  </code></pre>
  
  <p>But inspecting the ThriftHive.py file reveals the method execute within the Client class.</p>
  
  <p>How may I use Python to access Hive?</p>