================================
Project is currently unsupported
================================
.. image:: https://travis-ci.org/dropbox/PyHive.svg?branch=master
:target: https://travis-ci.org/dropbox/PyHive
.. image:: https://img.shields.io/codecov/c/github/dropbox/PyHive.svg
======
PyHive
======
PyHive is a collection of Python `DB-API <http://www.python.org/dev/peps/pep-0249/>`_ and
`SQLAlchemy <http://www.sqlalchemy.org/>`_ interfaces for `Presto <http://prestodb.io/>`_ and
`Hive <http://hive.apache.org/>`_.
Usage
=====
DB-API
------
.. code-block:: python
from pyhive import presto # or import hive or import trino
cursor = presto.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print cursor.fetchone()
print cursor.fetchall()
DB-API (asynchronous)
---------------------
.. code-block:: python
from pyhive import hive
from TCLIService.ttypes import TOperationState
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)
status = cursor.poll().operationState
while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):
logs = cursor.fetch_logs()
for message in logs:
print message
# If needed, an asynchronous query can be cancelled at any time with:
# cursor.cancel()
status = cursor.poll().operationState
print cursor.fetchall()
In Python 3.7 `async` became a keyword; you can use `async_` instead:
.. code-block:: python
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async_=True)
SQLAlchemy
----------
First install this package to register it with SQLAlchemy (see ``setup.py``).
.. code-block:: python
from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *
# Presto
engine = create_engine('presto://localhost:8080/hive/default')
# Trino
engine = create_engine('trino://localhost:8080/hive/default')
# Hive
engine = create_engine('hive://localhost:10000/default')
logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)
print select([func.count('*')], from_obj=logs).scalar()
# Hive + HTTPS + LDAP or basic Auth
engine = create_engine('hive+https://username:password@localhost:10000/')
logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)
print select([func.count('*')], from_obj=logs).scalar()
Note: query generation functionality is not exhaustive or fully tested, but there should be no
problem with raw SQL.
Passing session configuration
-----------------------------
.. code-block:: python
# DB-API
hive.connect('localhost', configuration={'hive.exec.reducers.max': '123'})
presto.connect('localhost', session_props={'query_max_run_time': '1234m'})
trino.connect('localhost', session_props={'query_max_run_time': '1234m'})
# SQLAlchemy
create_engine(
'presto://user@host:443/hive',
connect_args={'protocol': 'https',
'session_props': {'query_max_run_time': '1234m'}}
)
create_engine(
'trino://user@host:443/hive',
connect_args={'protocol': 'https',
'session_props': {'query_max_run_time': '1234m'}}
)
create_engine(
'hive://user@host:10000/database',
connect_args={'configuration': {'hive.exec.reducers.max': '123'}},
)
# SQLAlchemy with LDAP
create_engine(
'hive://user:password@host:10000/database',
connect_args={'auth': 'LDAP'},
)
Requirements
============
Install using
- ``pip install 'pyhive[hive]'`` for the Hive interface and
- ``pip install 'pyhive[presto]'`` for the Presto interface.
- ``pip install 'pyhive[trino]'`` for the Trino interface
PyHive works with
- Python 2.7 / Python 3
- For Presto: Presto install
- For Trino: Trino install
- For Hive: `HiveServer2 <https://cwiki.apache.org/confluence/display/Hive/Setting+up+HiveServer2>`_ daemon
Changelog
=========
See https://github.com/dropbox/PyHive/releases.
Contributing
============
- Please fill out the Dropbox Contributor License Agreement at https://opensource.dropbox.com/cla/ and note this in your pull request.
- Changes must come with tests, with the exception of trivial things like fixing comments. See .travis.yml for the test environment setup.
- Notes on project scope:
- This project is intended to be a minimal Hive/Presto client that does that one thing and nothing else.
Features that can be implemented on top of PyHive, such integration with your favorite data analysis library, are likely out of scope.
- We prefer having a small number of generic features over a large number of specialized, inflexible features.
For example, the Presto code takes an arbitrary ``requests_session`` argument for customizing HTTP calls, as opposed to having a separate parameter/branch for each ``requests`` option.
Testing
=======
.. image:: https://travis-ci.org/dropbox/PyHive.svg
:target: https://travis-ci.org/dropbox/PyHive
.. image:: http://codecov.io/github/dropbox/PyHive/coverage.svg?branch=master
:target: http://codecov.io/github/dropbox/PyHive?branch=master
Run the following in an environment with Hive/Presto::
./scripts/make_test_tables.sh
virtualenv --no-site-packages env
source env/bin/activate
pip install -e .
pip install -r dev_requirements.txt
py.test
WARNING: This drops/creates tables named ``one_row``, ``one_row_complex``, and ``many_rows``, plus a
database called ``pyhive_test_database``.
Updating TCLIService
====================
The TCLIService module is autogenerated using a ``TCLIService.thrift`` file. To update it, the
``generate.py`` file can be used: ``python generate.py <TCLIServiceURL>``. When left blank, the
version for Hive 2.3 will be downloaded.
Raw data
{
"_id": null,
"home_page": "https://github.com/dropbox/PyHive",
"name": "pyhive-fix",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Jing Wang",
"author_email": "jing@dropbox.com",
"download_url": "https://files.pythonhosted.org/packages/2f/9b/e81bd18f3f53e842993e152d59694935c975ca9bc68e357487dd12355dfe/pyhive_fix-0.6.3.dev0.tar.gz",
"platform": null,
"description": "================================\nProject is currently unsupported\n================================\n\n\n\n\n.. image:: https://travis-ci.org/dropbox/PyHive.svg?branch=master\n :target: https://travis-ci.org/dropbox/PyHive\n.. image:: https://img.shields.io/codecov/c/github/dropbox/PyHive.svg\n\n======\nPyHive\n======\n\nPyHive is a collection of Python `DB-API <http://www.python.org/dev/peps/pep-0249/>`_ and\n`SQLAlchemy <http://www.sqlalchemy.org/>`_ interfaces for `Presto <http://prestodb.io/>`_ and\n`Hive <http://hive.apache.org/>`_.\n\nUsage\n=====\n\nDB-API\n------\n.. code-block:: python\n\n from pyhive import presto # or import hive or import trino\n cursor = presto.connect('localhost').cursor()\n cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')\n print cursor.fetchone()\n print cursor.fetchall()\n\nDB-API (asynchronous)\n---------------------\n.. code-block:: python\n\n from pyhive import hive\n from TCLIService.ttypes import TOperationState\n cursor = hive.connect('localhost').cursor()\n cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)\n\n status = cursor.poll().operationState\n while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNING_STATE):\n logs = cursor.fetch_logs()\n for message in logs:\n print message\n\n # If needed, an asynchronous query can be cancelled at any time with:\n # cursor.cancel()\n\n status = cursor.poll().operationState\n\n print cursor.fetchall()\n\nIn Python 3.7 `async` became a keyword; you can use `async_` instead:\n\n.. code-block:: python\n\n cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async_=True)\n\n\nSQLAlchemy\n----------\nFirst install this package to register it with SQLAlchemy (see ``setup.py``).\n\n.. code-block:: python\n\n from sqlalchemy import *\n from sqlalchemy.engine import create_engine\n from sqlalchemy.schema import *\n # Presto\n engine = create_engine('presto://localhost:8080/hive/default')\n # Trino\n engine = create_engine('trino://localhost:8080/hive/default')\n # Hive\n engine = create_engine('hive://localhost:10000/default')\n logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)\n print select([func.count('*')], from_obj=logs).scalar()\n\n # Hive + HTTPS + LDAP or basic Auth\n engine = create_engine('hive+https://username:password@localhost:10000/')\n logs = Table('my_awesome_data', MetaData(bind=engine), autoload=True)\n print select([func.count('*')], from_obj=logs).scalar()\n\nNote: query generation functionality is not exhaustive or fully tested, but there should be no\nproblem with raw SQL.\n\nPassing session configuration\n-----------------------------\n\n.. code-block:: python\n\n # DB-API\n hive.connect('localhost', configuration={'hive.exec.reducers.max': '123'})\n presto.connect('localhost', session_props={'query_max_run_time': '1234m'})\n trino.connect('localhost', session_props={'query_max_run_time': '1234m'})\n # SQLAlchemy\n create_engine(\n 'presto://user@host:443/hive',\n connect_args={'protocol': 'https',\n 'session_props': {'query_max_run_time': '1234m'}}\n )\n create_engine(\n 'trino://user@host:443/hive',\n connect_args={'protocol': 'https',\n 'session_props': {'query_max_run_time': '1234m'}}\n )\n create_engine(\n 'hive://user@host:10000/database',\n connect_args={'configuration': {'hive.exec.reducers.max': '123'}},\n )\n # SQLAlchemy with LDAP\n create_engine(\n 'hive://user:password@host:10000/database',\n connect_args={'auth': 'LDAP'},\n )\n\nRequirements\n============\n\nInstall using\n\n- ``pip install 'pyhive[hive]'`` for the Hive interface and\n- ``pip install 'pyhive[presto]'`` for the Presto interface.\n- ``pip install 'pyhive[trino]'`` for the Trino interface\n\nPyHive works with\n\n- Python 2.7 / Python 3\n- For Presto: Presto install\n- For Trino: Trino install\n- For Hive: `HiveServer2 <https://cwiki.apache.org/confluence/display/Hive/Setting+up+HiveServer2>`_ daemon\n\nChangelog\n=========\nSee https://github.com/dropbox/PyHive/releases.\n\nContributing\n============\n- Please fill out the Dropbox Contributor License Agreement at https://opensource.dropbox.com/cla/ and note this in your pull request.\n- Changes must come with tests, with the exception of trivial things like fixing comments. See .travis.yml for the test environment setup.\n- Notes on project scope:\n\n - This project is intended to be a minimal Hive/Presto client that does that one thing and nothing else.\n Features that can be implemented on top of PyHive, such integration with your favorite data analysis library, are likely out of scope.\n - We prefer having a small number of generic features over a large number of specialized, inflexible features.\n For example, the Presto code takes an arbitrary ``requests_session`` argument for customizing HTTP calls, as opposed to having a separate parameter/branch for each ``requests`` option.\n\nTesting\n=======\n.. image:: https://travis-ci.org/dropbox/PyHive.svg\n :target: https://travis-ci.org/dropbox/PyHive\n.. image:: http://codecov.io/github/dropbox/PyHive/coverage.svg?branch=master\n :target: http://codecov.io/github/dropbox/PyHive?branch=master\n\nRun the following in an environment with Hive/Presto::\n\n ./scripts/make_test_tables.sh\n virtualenv --no-site-packages env\n source env/bin/activate\n pip install -e .\n pip install -r dev_requirements.txt\n py.test\n\nWARNING: This drops/creates tables named ``one_row``, ``one_row_complex``, and ``many_rows``, plus a\ndatabase called ``pyhive_test_database``.\n\nUpdating TCLIService\n====================\n\nThe TCLIService module is autogenerated using a ``TCLIService.thrift`` file. To update it, the\n``generate.py`` file can be used: ``python generate.py <TCLIServiceURL>``. When left blank, the\nversion for Hive 2.3 will be downloaded.\n",
"bugtrack_url": null,
"license": "Apache License, Version 2.0",
"summary": "Python interface to Hive",
"version": "0.6.3.dev0",
"project_urls": {
"Homepage": "https://github.com/dropbox/PyHive"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "47bbb7a897d41c4533ba1d1a92eac38dae36537732386f92ee516cee01269e1d",
"md5": "aff52dd69cf1ff9ac8ac81a5c56b2fb0",
"sha256": "431caadf0999a57d3d320fa3e1e8b296331d01a23aea2491e57da35b16673786"
},
"downloads": -1,
"filename": "pyhive_fix-0.6.3.dev0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aff52dd69cf1ff9ac8ac81a5c56b2fb0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 51898,
"upload_time": "2023-06-19T09:56:03",
"upload_time_iso_8601": "2023-06-19T09:56:03.811108Z",
"url": "https://files.pythonhosted.org/packages/47/bb/b7a897d41c4533ba1d1a92eac38dae36537732386f92ee516cee01269e1d/pyhive_fix-0.6.3.dev0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2f9be81bd18f3f53e842993e152d59694935c975ca9bc68e357487dd12355dfe",
"md5": "5fe537290763d1acadeb4e2c40e68512",
"sha256": "3befaeb5d621fac369e0b2a7f03344ba89c9d54e9596eaddbaccd49f1f42bb2c"
},
"downloads": -1,
"filename": "pyhive_fix-0.6.3.dev0.tar.gz",
"has_sig": false,
"md5_digest": "5fe537290763d1acadeb4e2c40e68512",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 46644,
"upload_time": "2023-06-19T09:56:06",
"upload_time_iso_8601": "2023-06-19T09:56:06.582160Z",
"url": "https://files.pythonhosted.org/packages/2f/9b/e81bd18f3f53e842993e152d59694935c975ca9bc68e357487dd12355dfe/pyhive_fix-0.6.3.dev0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-19 09:56:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dropbox",
"github_project": "PyHive",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"lcname": "pyhive-fix"
}