SQL Connectors & Frameworks
This guide covers User-Agent configuration for SQL connectors and frameworks that work with Databricks.
Python SQL Connector
For the Databricks SQL Connector for Python, include the User-Agent identifier using the _user_agent_entry parameter (note the leading underscore) when creating the connection:
from databricks import sql
import os
with sql.connect(
server_hostname=os.getenv("DATABRICKS_HOST"),
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
credentials_provider=credential_provider,
_user_agent_entry="<isv-name_product-name>/<product-version>"
) as connection:
# Your code here
pass
SQLAlchemy
For SQLAlchemy, set the User-Agent identifier through the user_agent_entry parameter in the create_engine() configuration under connect_args:
from sqlalchemy import create_engine
engine = create_engine(
"databricks+pyodbc://token:<ACCESS_TOKEN>@<SERVER_HOST>:443",
connect_args={
"http_path": "<HTTP_PATH>",
"user_agent_entry": "<isv-name_product-name>/<product-version>"
}
)
PyODBC (Databricks ODBC driver)
For PyODBC, include the UserAgentEntry parameter in your connection setup.
DSN connection
import pyodbc
conn = pyodbc.connect(
"DSN=<dsn-name>;UserAgentEntry=<isv-name_product-name>/<product-version>",
autocommit=True
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM samples.nyctaxi.trips")
for row in cursor.fetchall():
print(row)
DSN-less connection
import pyodbc
import os
conn = pyodbc.connect(
"Driver=/Library/simba/spark/lib/libsparkodbc_sb64-universal.dylib;"
f"Host={os.getenv('DATABRICKS_HOST')};"
"Port=443;"
f"HTTPPath={os.getenv('DATABRICKS_HTTP_PATH')};"
"SSL=1;"
"ThriftTransport=2;"
"UserAgentEntry=<isv-name_product-name>/<product-version>;",
autocommit=True
)
What's next
- Configure SDKs: Set up User-Agent telemetry for Databricks SDKs. See SDKs.
- Configure SQL drivers: Set up telemetry for JDBC and ODBC drivers. See SQL Drivers.
- Review User-Agent format: Understand the required format and guidelines. See Telemetry & Attribution.