Git Product home page Git Product logo

python-phoenixdb's Introduction

Phoenix database adapter for Python

Build Status Documentation Status

phoenixdb is a Python library for accessing the Phoenix SQL database using the remote query server. The library implements the standard DB API 2.0 interface, which should be familiar to most Python programmers.

Installation

The easiest way to install the library is using pip:

pip install phoenixdb

You can also download the source code from GitHub, extract the archive and then install it manually:

cd /path/to/python-phoenix-x.y.z/
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 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

To create or update the Avatica protobuf classes, change the tag in gen-protobuf.sh and run the script.

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

docker-compose up

Or if you need an older version of Phoenix:

PHOENIX_VERSION=4.9 docker-compose up

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

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

Commits to the master branch are automatically tested against all supported versions of Phoenix. You can see the results here.

Known issues

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

python-phoenixdb's People

Contributors

ankitsinghal avatar joshelser avatar lalinsky avatar mheppner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.