pax_global_header00006660000000000000000000000064126276563300014524gustar00rootroot0000000000000052 comment=35d0211b3e52fd0e35b2841676d3c446a27b5d97 vertica-python-0.5.5/000077500000000000000000000000001262765633000145075ustar00rootroot00000000000000vertica-python-0.5.5/.gitignore000066400000000000000000000006171262765633000165030ustar00rootroot00000000000000*.py[cod] test.py # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib64 # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject .DS_Store *.iml # vagrant .vagrant # pycharm /.idea/ # default virtual environment /env/ vertica-python-0.5.5/LICENSE000066400000000000000000000020731262765633000155160ustar00rootroot00000000000000vertica-python Copyright (c) 2013 Uber Technologies, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vertica-python-0.5.5/MANIFEST.in000066400000000000000000000002101262765633000162360ustar00rootroot00000000000000include LICENSE include requirements.txt include README.md recursive-include vertica_python *.py recursive-exclude vertica_python *.pyc vertica-python-0.5.5/README.md000066400000000000000000000126451262765633000157760ustar00rootroot00000000000000# vertica-python [![PyPI version](https://badge.fury.io/py/vertica-python.png)](http://badge.fury.io/py/vertica-python) 0.5.x changes the connection method to accept kwargs instead of a dict to be more dbapi compliant. copy methods improved and consolidated in 0.5.1 0.4.x breaks some of the older query interfaces (row_handler callback, and connection.query). It replaces the row_handler callback with an iterate() method. Please see examples below If you are on 0.4.x, please upgrade to 0.4.6 as there are various bug fixes vertica-python is a native Python adapter for the Vertica (http://www.vertica.com) database. vertica-python is currently in beta stage; it has been tested for functionality and has a very basic test suite. Please use with caution, and feel free to submit issues and/or pull requests (after running the unit tests). vertica-python has been tested with Vertica 6.1.2/7.0.0+ and Python 2.6/2.7. ## Installation If you're using pip >= 1.4 and you don't already have pytz installed: pip install --pre pytz To install vertica-python with pip: pip install vertica-python To install vertica-python with pip (with optional namedparams dependencies): # see 'Using named parameters' section below pip install 'vertica-python[namedparams]' Source code for vertica-python can be found at: http://github.com/uber/vertica-python ## Run unit tests # install nose if you don't have it pip install -r requirements_test.txt # you will need to have access to a vertica database. # connection info is in tests/basic_tests.py # run tests nosetests ## Usage **Create connection** ```python import vertica_python conn_info = {'host': '127.0.0.1', 'port': 5433, 'user': 'some_user', 'password': 'some_password', 'database': 'a_database', # 10 minutes timeout on queries 'read_timeout': 600} # simple connection, with manual close connection = vertica_python.connect(**conn_info) # do things connection.close() # using with for auto connection closing after usage with vertica_python.connect(**conn_info) as connection: # do things ``` **Stream query results**: ```python cur = connection.cursor() cur.execute("SELECT * FROM a_table LIMIT 2") for row in cur.iterate(): print(row) # [ 1, 'some text', datetime.datetime(2014, 5, 18, 6, 47, 1, 928014) ] # [ 2, 'something else', None ] ``` Streaming is recommended if you want to further process each row, save the results in a non-list/dict format (e.g. Pandas DataFrame), or save the results in a file. **In-memory results as list**: ```python cur = connection.cursor() cur.execute("SELECT * FROM a_table LIMIT 2") cur.fetchall() # [ [1, 'something'], [2, 'something_else'] ] ``` **In-memory results as dictionary**: ```python cur = connection.cursor('dict') cur.execute("SELECT * FROM a_table LIMIT 2") cur.fetchall() # [ {'id': 1, 'value': 'something'}, {'id': 2, 'value': 'something_else'} ] connection.close() ``` **Query using named parameters**: ```python # Using named parameter bindings requires psycopg2>=2.5.1 which is not includes with the base vertica_python requirements. cur = connection.cursor() cur.execute("SELECT * FROM a_table WHERE a = :propA b = :propB", {'propA': 1, 'propB': 'stringValue'}) cur.fetchall() # [ [1, 'something'], [2, 'something_else'] ] ``` **Insert and commits** : ```python cur = connection.cursor() # inline commit cur.execute("INSERT INTO a_table (a, b) VALUES (1, 'aa'); commit;") # commit in execution cur.execute("INSERT INTO a_table (a, b) VALUES (1, 'aa')") cur.execute("INSERT INTO a_table (a, b) VALUES (2, 'bb')") cur.execute("commit;") # connection.commit() cur.execute("INSERT INTO a_table (a, b) VALUES (1, 'aa')") connection.commit() ``` **Copy** : ```python cur = connection.cursor() cur.copy("COPY test_copy (id, name) from stdin DELIMITER ',' ", csv) ``` Where `csv` is either a string or a file-like object (specifically, any object with a `read()` method). If using a file, the data is streamed. ## Rowcount oddities vertica_python behaves a bit differently than dbapi when returning rowcounts. After a select execution, the rowcount will be -1, indicating that the row count is unknown. The rowcount value will be updated as data is streamed. ```python cur.execute('SELECT 10 things') cur.rowcount == -1 # indicates unknown rowcount cur.fetchone() cur.rowcount == 1 cur.fetchone() cur.rowcount == 2 cur.fetchall() cur.rowcount == 10 ``` After an insert/update/delete, the rowcount will be returned as a single element row: ```python cur.execute("DELETE 3 things") cur.rowcount == -1 # indicates unknown rowcount cur.fetchone()[0] == 3 ``` ## Nextset If you execute multiple statements in a single call to execute(), you can use cursor.nextset() to retrieve all of the data. ```python cur.execute('SELECT 1; SELECT 2;') cur.fetchone() # [1] cur.fetchone() # None cur.nextset() # True cur.fetchone() # [2] cur.fetchone() # None cur.nextset() # None ``` ## License MIT License, please see `LICENSE` for details. ## Acknowledgements Many thanks go to the contributors to the Ruby Vertica gem (https://github.com/sprsquish/vertica), since they did all of the wrestling with Vertica's protocol and have kept the gem updated. They are: * [Matt Bauer](http://github.com/mattbauer) * [Jeff Smick](http://github.com/sprsquish) * [Willem van Bergen](http://github.com/wvanbergen) * [Camilo Lopez](http://github.com/camilo) vertica-python-0.5.5/Vagrantfile000066400000000000000000000031521262765633000166750ustar00rootroot00000000000000# -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" ####################################################################### # This will set up a box with Vertica Community Edition 7.1.1 # running inside the box in a Docker container. # # The purpose is to have a Vertica instance that can be used by tests. # # Vertica's port 5433 is exposed to host machine. # Database 'docker' is available. # User is 'dbadmin' with no password. # # >>> # ! As is, any data stored inside Vertica will not live through # ! container or VM restart. # >>> ####################################################################### # Globally install docker - bypass default Vagrant docker installation # procedure because it does not work reliably (curl does not follow # redirect = Docker won't be installed) $install_docker = <