Python Driver
Use the Phoenix DB-API Python driver with Phoenix Query Server.
The Python driver for Apache Phoenix implements the Python DB 2.0 API to access Phoenix via Phoenix Query Server. The driver is tested with Python 2.7 and 3.5-3.8. This code was originally called python-phoenixdb and was graciously donated by its authors to the Apache Phoenix project.
All future development of the project is being done in Apache Phoenix.
Installation
From PyPI
The latest release is always available from PyPI, and can be installed by
pip/pip3 as usual.
pip3 install --user phoenixdbFrom source
You can build phoenixdb from the official source release,
or use the latest development version from the source
repository. The python-phoenixdb source
lives in the python-phoenixdb directory of the phoenix-queryserver
repository.
$ cd python-phoenixdb # (Only when building from the git repo)
$ pip install -r requirements.txt
$ python setup.py installExamples
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'])Limitations
- None presently known.
Resources
- PHOENIX-4636: Initial landing of the driver into Apache Phoenix.
- PHOENIX-4688: Implementation of Kerberos authentication via SPNEGO.