databricks-dbapi

raw JSON →
0.6.0 verified Mon Apr 27 auth: no python

A DBAPI 2.0 interface and SQLAlchemy dialect for Databricks interactive clusters. Current version 0.6.0, supports Python >=2.7 (excludes 3.0-3.4). Release cadence is irregular; latest releases: 0.4.0, 0.5.0, 0.6.0.

pip install databricks-dbapi
error ImportError: No module named 'databricks_dbapi'
cause The package is named 'databricks-dbapi' on PyPI but import uses underscores.
fix
Ensure you installed 'databricks-dbapi' (pip install databricks-dbapi) and import as 'databricks_dbapi'.
error thrift.transport.TTransport.TTransportException: Could not connect to ...
cause Thrift connection failure due to incorrect server_hostname, port (default 443), or network/firewall blocking.
fix
Verify server_hostname includes port: 'host:443'. For HTTP, use transport='http' (default).
error TypeError: __init__() got an unexpected keyword argument 'access_token'
cause Access token parameter was introduced in version 0.5.0; using older version expects 'token' instead.
fix
Update to >=0.5.0 or use 'token'=... in older versions.
error sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'databricks://...'
cause Using non-standard prefix 'databricks://' without http or thrift.
fix
Use 'databricks+http://token:secret@host:443/path' or 'databricks+thrift://...'
breaking Version 0.5.0 removed support for Python 3.5 and earlier; ensure Python 3.6+.
fix Use Python 3.6+ or pin to databricks-dbapi==0.4.0.
gotcha The default connection uses HTTP (REST API), but if you need HiveServer2 Thrift, you must explicitly specify transport='thrift'.
fix Connection(..., transport='thrift')
deprecated The SQLAlchemy dialect uses 'databricks+http://' or 'databricks+thrift://'; the plain 'databricks://' prefix may be removed in future.
fix Use 'databricks+http://' or 'databricks+thrift://' explicitly.
gotcha Timeout errors often occur if server_hostname or http_path are incorrect; they are not validated until a query is run.
fix Double-check server_hostname (e.g., 'dbc-...cloud.databricks.com') and http_path (from SQL Warehouse settings).

Connect to Databricks interactive cluster using HTTP (default) with personal access token.

from databricks_dbapi import Connection

conn = Connection(
    server_hostname='your-databricks-instance.cloud.databricks.com',
    http_path='/sql/1.0/warehouses/your-warehouse-id',
    access_token=os.environ.get('DATABRICKS_TOKEN', '')
)
cursor = conn.cursor()
cursor.execute('SELECT current_timestamp')
print(cursor.fetchall())