Skip to main content

phoenixdb is a Python library for accessing Apache Phoenix using the remote query server. This library implements the standard DB API 2.0 interface and a subset of SQLAlchemy, either of which should be familiar to most Python programmers.

Installation from PyPI

The easiest way to install the latest official release of phoenixdb is from PyPI:

pip install phoenixdb

Installation from Source

The 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
pip install -r requirements.txt
python setup.py install

Note that old versions of pip and setuptools have various bugs and incompatibilities that may result in installation errors, especially on old python versions. If you encounter problems while building, update your pip and setuptools, and try again:

pip install --upgrade pip
pip install --upgrade setuptools

Usage

The 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 environment

If you want to quickly try out the included examples, you can set up a local virtualenv with all the necessary requirements:

virtualenv e
source e/bin/activate
pip install -r requirements.txt
python setup.py develop

You can start a Phoenix QueryServer instance on http://localhost:8765 for testing by running the following command in the pohoenix-queryserver-parent directory:

mvn clean verify -Pshade-javax-servlet -am -pl phoenix-queryserver-it -Dtest=foo \
-Dit.test=QueryServerBasicsIT#startLocalPQS \
-Ddo.not.randomize.pqs.port=true -Dstart.unsecure.pqs=true

You can start a secure (https+kerberos) Phoenix QueryServer instance on https://localhost:8765 for testing by running the following command in the phoenix-queryserver-parent directory:

mvn clean verify -Pshade-javax-servlet -am -pl phoenix-queryserver-it -Dtest=foo \
-Dit.test=SecureQueryServerPhoenixDBIT#startLocalPQS \
-Ddo.not.randomize.pqs.port=true -Dstart.secure.pqs=true

this 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.

Note: Depending on the Phoenix version used for building, you may or may not need the -Pshade-javax-servlet option. See BUILDING.md in the repository root for more information.

If you want to use the library without installing the phoenixdb library, you can use the PYTHONPATH environment 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.py

Don’t forget to run flake8 on your changes.

Running the test suite

The 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 the PHOENIXDB_TEST_DB_URL environment variable:

export PHOENIXDB_TEST_DB_URL='http://localhost:8765/'
tox

If you use a secure PQS server, you can set the connection parameters via the following environment variables:

  • PHOENIXDB_TEST_DB_TRUSTSTORE

  • PHOENIXDB_TEST_DB_AUTHENTICATION

  • PHOENIXDB_TEST_DB_AVATICA_USER

  • PHOENIXDB_TEST_DB_AVATICA_PASSWORD

Similarly, 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' tox

You 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 toxtest

You 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=true

Known issues

  • When using phoenixdb 1.2.0 or later with Python 2, phoenixdb will not work unless the Python protobuf library uses the ‘cpp’ implementation. See https://issues.apache.org/jira/browse/PHOENIX-6863 on how to work around the issue.

  • TIME 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 support

SQLAlchemy 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:

All other API should be considered not implemented.

Metadata

Release files for phoenixdb 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phoenixdb 1.2.2
File Size Uploaded
phoenixdb-1.2.2.tar.gz 51.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for phoenixdb 1.2.2
File Interpreter ABI Platform
phoenixdb-1.2.2-py3-none-any.whl Python 3 none any Details
phoenixdb-1.2.2-py2-none-any.whl Python 2 none any Details

Total release size: 180.3 kB

Release files / phoenixdb-1.2.2.tar.gz

Download URL phoenixdb-1.2.2.tar.gz
Size 51.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bd177f5d7cd6ad482cc5127fe41062cf37553d2ce51f12c4b6687028966761fd
BLAKE2b-256 checksum
How to use checksums
ea002b44dcb27e82c1331e57540adfb25bf05214191a02d8801f260e24764740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.11

Release files / phoenixdb-1.2.2-py3-none-any.whl

Download URL phoenixdb-1.2.2-py3-none-any.whl
Size 64.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0251e6e5f90ef6a13a67aee158fdbe43ed13ff3c9147e1967de24555023d5d7
BLAKE2b-256 checksum
How to use checksums
f0ddab0b46b6a2702d9c58936a958ca047ed02f56cc755774b9dd63c5356992c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.11

Release files / phoenixdb-1.2.2-py2-none-any.whl

Download URL phoenixdb-1.2.2-py2-none-any.whl
Size 64.5 kB
Tags Python 2
SHA-256 checksum
How to use checksums
947d4049b728de9645e704b529e044ff454d502b77d9770bdcacd7b72757b403
BLAKE2b-256 checksum
How to use checksums
bc46e54a5119852e6e63fd0485b77bd6144cacb63c0c7119b2f7965168f3fe7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.11

Release history Release notifications | RSS feed

This release

1.2.2 This release

3 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.0

3 release files

1.0.1

3 release files

1.0.0

3 release files

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page