Skip to main content

Phoenix database adapter for Python

https://travis-ci.org/Pirionfr/pyPhoenix.svg?branch=master https://img.shields.io/pypi/v/pyPhoenix.svg https://img.shields.io/pypi/pyversions/pyPhoenix.svg Requirements Status

pyphoenix is a Python library for accessing the Phoenix SQL database using the remote query server introduced in Phoenix 4.4. The library implements the standard DB API 2.0 interface, which should be familiar to most Python programmers. It include sqlachemy plugins.

Installation

The easiest way to install the library is using pip:

pip install pyPhoenix

You can also download the source code and install it manually:

cd /path/to/pyphoenix/
python setup.py install

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 pyphoenix

database_url = 'http://localhost:8765/'
conn = pyphoenix.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()

Phoenix versions

Phoenix 4.7 uses a serialization based on Protocol Buffers (proto3) by default.

This library only supports Protocol serialization.

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

If you need a Phoenix server for experimenting, you can get one running quickly using Vagrant:

vagrant up

You can connect to the virtual machine and work with the Phoenix shell from there:

vagrant ssh
/opt/phoenix/bin/sqlline.py localhost

Interactive SQL shell

There is a Python-based interactive shell include in the examples folder, which can be used to connect to Phoenix and execute queries:

./examples/shell.py http://localhost:8765/
db=> CREATE TABLE test (id INTEGER PRIMARY KEY, name VARCHAR);
no rows affected (1.363 seconds)
db=> UPSERT INTO test (id, name) VALUES (1, 'Lukas');
1 row affected (0.004 seconds)
db=> SELECT * FROM test;
+------+-------+
|   ID | NAME  |
+======+=======+
|    1 | Lukas |
+------+-------+
1 row selected (0.019 seconds)

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 pyphoenix_TEST_DB_URL environment variable:

export pyphoenix_TEST_DB_URL='http://localhost:8765/'
nosetests

Known issues

  • In general, the library has not been battle-tested yet. You might encounter almost any problem. Use with care.

  • You can only use the library in autocommit mode. The native Java Phoenix library also implements batched upserts, which can be committed at once, but this is not exposed over the remote server. (CALCITE-767)

  • 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)

  • ARRAY columns are not supported. (CALCITE-1050, PHOENIX-2585)

SQLachemy

  • Creates versions for select

  • select over queryserver with pyphoenix

Usage

example:

import sqlalchemy

db = sqlalchemy.create_engine('phoenix://localhost:8765/')
conn = db.connect()

Release files for pyPhoenix 0.12.0

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

Source distribution (sdist)

Source distribution for pyPhoenix 0.12.0
File Size Uploaded
pyPhoenix-0.12.0.tar.gz 37.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyPhoenix 0.12.0
File Interpreter ABI Platform
pyPhoenix-0.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 80.3 kB

Release files / pyPhoenix-0.12.0.tar.gz

Download URL pyPhoenix-0.12.0.tar.gz
Size 37.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ac621d22fff72934471555c7bdcda51bba4b70c34a432504c9e14052d6f651aa
BLAKE2b-256 checksum
How to use checksums
ea6487a01d7ae72ddf6155413d3301d8f199ba86b718777eaf417af60550b702
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

Release files / pyPhoenix-0.12.0-py3-none-any.whl

Download URL pyPhoenix-0.12.0-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
402734a00be722050801ec55672dda9e543fc82fc820a45e761ef772c46367d0
BLAKE2b-256 checksum
How to use checksums
8058253e3c9afc780ebe8a447ba583d85062086c56052c0afb376bc0ebd67e38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.11.0

1 release file

0.10.0

1 release file

0.9.4

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