Jupyter magic commands for Databricks SQL queries
Project description
db-magic
Jupyter magic commands for Databricks SQL queries with OAuth authentication.
Installation
pip install db-magic
For development:
git clone https://github.com/williebsweet/db_magic.git
cd db_magic
pip install -e .
Configuration
Set environment variables for your Databricks workspace:
export DATABRICKS_HOST='https://your-workspace.cloud.databricks.com'
export DATABRICKS_HTTP_PATH='/sql/1.0/warehouses/your-warehouse-id'
Or create ~/.databricks/config.json:
{
"server_hostname": "https://your-workspace.cloud.databricks.com",
"http_path": "/sql/1.0/warehouses/your-warehouse-id"
}
Usage
Load the extension
%load_ext db_magic
Cell magic: %%sql
Execute multi-line SQL queries:
%%sql results
SELECT * FROM my_table LIMIT 100
Results are stored in the variable results (or _df by default).
Line magic: %sql_line
Execute single-line queries:
%sql_line SELECT count(*) FROM users
# Store in a specific variable
%sql_line count = SELECT count(*) FROM users
Variable substitution
Use {variable} syntax to inject Python variables into queries:
user_id = 123
table = 'users'
%%sql
SELECT * FROM {table} WHERE id = {user_id}
Strings are automatically quoted; numbers are inserted as-is.
Suppress auto-display
For large queries where you don't want automatic display:
%%sql --no-display big_df
SELECT * FROM huge_table
Or use the short form:
%%sql -q big_df
SELECT * FROM huge_table
Check configuration
# Show current config
%databricks_config
# Test authentication
%databricks_config --show-auth
Features
- OAuth authentication via browser
- Query timing display
- Auto-display of first 10 rows
- Variable substitution in queries
- Both cell (
%%sql) and line (%sql_line) magics --no-displayflag for large queries- Error display with HTML formatting
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file db_magic-0.1.1.tar.gz.
File metadata
- Download URL: db_magic-0.1.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0de2f9989820f302a0d3dc20e154dc18f7fc0a9afed5c693972a91697f4f943c
|
|
| MD5 |
6cbf47202c6346c64b0f64ac41c0450c
|
|
| BLAKE2b-256 |
8d0e5092a5c67e84eac0622f33c0a2612ca67d065dd9ea194172de0140abf1de
|
Provenance
The following attestation bundles were made for db_magic-0.1.1.tar.gz:
Publisher:
publish.yml on williebsweet/db_magic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_magic-0.1.1.tar.gz -
Subject digest:
0de2f9989820f302a0d3dc20e154dc18f7fc0a9afed5c693972a91697f4f943c - Sigstore transparency entry: 1285727130
- Sigstore integration time:
-
Permalink:
williebsweet/db_magic@61c0f558e63a0f19e6add0181aca9abb4851f781 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/williebsweet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61c0f558e63a0f19e6add0181aca9abb4851f781 -
Trigger Event:
release
-
Statement type:
File details
Details for the file db_magic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: db_magic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
117749230253fce14b172bbdda58a8b1e96fb06115c8e8a00a04aebf8e8df7ed
|
|
| MD5 |
ca9d60e5faa6ab048aeb5c117c399935
|
|
| BLAKE2b-256 |
2322815db98792ca89322cc37f174cea6706db1c6f5295f6109ca00daeddd689
|
Provenance
The following attestation bundles were made for db_magic-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on williebsweet/db_magic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_magic-0.1.1-py3-none-any.whl -
Subject digest:
117749230253fce14b172bbdda58a8b1e96fb06115c8e8a00a04aebf8e8df7ed - Sigstore transparency entry: 1285727246
- Sigstore integration time:
-
Permalink:
williebsweet/db_magic@61c0f558e63a0f19e6add0181aca9abb4851f781 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/williebsweet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61c0f558e63a0f19e6add0181aca9abb4851f781 -
Trigger Event:
release
-
Statement type: