Skip to main content

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-display flag for large queries
  • Error display with HTML formatting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_magic-0.1.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_magic-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

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

Hashes for db_magic-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0de2f9989820f302a0d3dc20e154dc18f7fc0a9afed5c693972a91697f4f943c
MD5 6cbf47202c6346c64b0f64ac41c0450c
BLAKE2b-256 8d0e5092a5c67e84eac0622f33c0a2612ca67d065dd9ea194172de0140abf1de

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_magic-0.1.1.tar.gz:

Publisher: publish.yml on williebsweet/db_magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for db_magic-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 117749230253fce14b172bbdda58a8b1e96fb06115c8e8a00a04aebf8e8df7ed
MD5 ca9d60e5faa6ab048aeb5c117c399935
BLAKE2b-256 2322815db98792ca89322cc37f174cea6706db1c6f5295f6109ca00daeddd689

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_magic-0.1.1-py3-none-any.whl:

Publisher: publish.yml on williebsweet/db_magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page