Package: phoenixdb
phoenixdbis a Python library for accessingApache Phoenixusing theremote query server.
This library implements the
standardDB API 2.0interface and a
subset ofSQLAlchemy, either of which should be familiar
to most Python programmers.InstallationThe source code is part of the phoenix-queryserver source distribution.
You can download it from <https://phoenix.apache.org/>, or get the latest development version
from <https://github.com/apache/phoenix-queryserver>Extract the archive and then install it manually:cd /path/to/phoenix-queryserver-x.y.z/python/phoenixdb
python setup.py installUsageThe library implements the standard DB API 2.0 interface, so it can be
used the same way you would use any other SQL database from Python, for example:import phoenixdb
import phoenixdb.cursor

database_url = 'http://localhost:8765/'
conn = phoenixdb.connect(database_url, autocommit=True)

cursor = conn.cursor()
cursor.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username VARCHAR)")
cursor.execute("UPSERT INTO users VALUES (?, ?)", (1, 'admin'))
cursor.execute("SELECT * FROM users")
print(cursor.fetchall())

cursor = conn.cursor(cursor_factory=phoenixdb.cursor.DictCursor)
cursor.execute("SELECT * FROM users WHERE id=1")
print(cursor.fetchone()['USERNAME'])Setting up a development environmentIf you want to quickly try out the included examples, you can set up a
localvirtualenvwith all the
necessary requirements:virtualenv e
source e/bin/activate
pip install -r requirements.txt
python setup.py developYou can start a Phoenix QueryServer instance onhttp://localhost:8765for testing by running
the following command in the pohoenix-queryserver-parent directory:mvn clean verify -am -pl phoenix-queryserver-it -Dtest=foo \
-Dit.test=QueryServerBasicsIT#startLocalPQS \
-Ddo.not.randomize.pqs.port=true -Dstart.unsecure.pqs=trueYou can start a secure (https+kerberos) Phoenix QueryServer instance onhttps://localhost:8765for testing by running the following command in the phoenix-queryserver-parent directory:mvn clean verify -am -pl phoenix-queryserver-it -Dtest=foo \
-Dit.test=SecureQueryServerPhoenixDBIT#startLocalPQS \
-Ddo.not.randomize.pqs.port=true -Dstart.secure.pqs=truethis will also create a shell script in phoenix-queryserver-it/target/krb_setup.sh, that you can use to set
up the environment for the tests.If you want to use the library without installing the phoenixdb library, you can use
thePYTHONPATHenvironment variable to point to the library directly:cd phoenix-queryserver-parent/python-phoenixdb
python setup.py build
cd ~/my_project
PYTHONPATH=$PHOENIX_HOME/build/lib python my_app.pyDon’t forget to run flake8 on your changes.Running the test suiteThe library comes with a test suite for testing Python DB API 2.0 compliance and
various Phoenix-specific features. In order to run the test suite, you need a
working Phoenix database and set thePHOENIXDB_TEST_DB_URLenvironment variable:export PHOENIXDB_TEST_DB_URL='http://localhost:8765/'
toxIf you use a secure PQS server, you can set the connection parameters via the following environment
variables:PHOENIXDB_TEST_DB_TRUSTSTOREPHOENIXDB_TEST_DB_AUTHENTICATIONPHOENIXDB_TEST_DB_AVATICA_USERPHOENIXDB_TEST_DB_AVATICA_PASSWORDSimilarly, tox can be used to run the test suite against multiple Python versions:pyenv install 3.5.5
pyenv install 3.6.4
pyenv install 2.7.14
pyenv global 2.7.14 3.5.5 3.6.4
PHOENIXDB_TEST_DB_URL='http://localhost:8765' toxYou can use tox and docker to run the tests on supported python versions without
installing the environments locally:docker build -t toxtest .
docker run --rm --add-host=host.docker.internal:host-gateway -v `pwd`:/src toxtestYou can also run the test suite from maven as part of the Java build by setting the
run.full.python.testsuite property. You DO NOT need to set the PHOENIXDB_* enviroment variables,
maven will set them up for you. The output of the test run will be saved in
phoenix-queryserver/phoenix-queryserver-it/target/python-stdout.log and python-stderr.log:mvn clean verify -Drun.full.python.testsuite=trueKnown issuesTIME and DATE columns in Phoenix are stored as full timestamps with a millisecond accuracy,
but the remote protocol only exposes the time (hour/minute/second) or date (year/month/day)
parts of the columns. (CALCITE-797,CALCITE-798)TIMESTAMP columns in Phoenix are stored with a nanosecond accuracy, but the remote protocol truncates them to milliseconds. (CALCITE-796)SQLAlchemy feature supportSQLAlchemy has a wide breadth of API, ranging from basic SQL commands to object-relational mapping support.Today, python-phoenixdb only supports the following subset of the complete SQLAlchemy API:Textual SQLAll other API should be considered not implemented.