Python Driver for Phoenix

The Python Driver for Apache Phoenix implements the Python DB 2.0 API to access Phoenix via the Phoenix Query Server. The driver is tested with Python 2.7, 3.5, and 3.6. 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

Phoenix does not presently deploy the driver, so users must first build the driver and install it themselves:

  1. $ cd python
  2. $ pip install -r requirements.txt
  3. $ python setup.py install

Deploying a binary release to central Python package-hosting services (e.g. installable via pip) will be done eventually. Presently, releases are in source-form only.

Examples

  1. import phoenixdb
  2. import phoenixdb.cursor
  3.  
  4. database_url = 'http://localhost:8765/'
  5. conn = phoenixdb.connect(database_url, autocommit=True)
  6.  
  7. cursor = conn.cursor()
  8. cursor.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username VARCHAR)")
  9. cursor.execute("UPSERT INTO users VALUES (?, ?)", (1, 'admin'))
  10. cursor.execute("SELECT * FROM users")
  11. print(cursor.fetchall())
  12.  
  13. cursor = conn.cursor(cursor_factory=phoenixdb.cursor.DictCursor)
  14. cursor.execute("SELECT * FROM users WHERE id=1")
  15. print(cursor.fetchone()['USERNAME'])

Limitations

  • The driver presently does not support Kerberos authentication PHOENIX-4688

Resources

  • PHOENIX-4636 : Initial landing of the driver into Apache Phoenix.

原文: http://phoenix.apache.org/python.html