Skip to main content

esje — Credential-Safe SQL Magic & Live Dashboards for Jupyter

PyPI Version Python Versions License: MIT Framework: IPython

E.S.J.E — Easy. SQL. Jupyter. Engine.

esje brings powerful, credential-safe %sql and %%sql magics to Jupyter Notebooks and JupyterLab. Designed for data analysts and engineers, it eliminates hardcoded secrets in .ipynb files, seamlessly executes SQL alongside Python visualization code, and provides non-blocking auto-refreshing --live dashboards with Play/Pause/Stop controls.


✨ Features

  • 🌐 Login with Google: One-click browser OAuth2 login for BigQuery — no service account JSON required.
  • 🔒 Zero Hardcoded Secrets: Interactive prompts and automatic .env / environment variable fallbacks prevent password leaks in notebooks, git commits, or exports.
  • ☁️ Google BigQuery Native Driver: Query BigQuery directly via browser login, Application Default Credentials (ADC), or service account key files.
  • ⚡ PyArrow High-Performance Backend: Optional PyArrow integration for memory-efficient, fast query execution on large datasets.
  • 📊 SQL + Python Inline Execution: Write SQL queries and Python plotting code (matplotlib, seaborn, plotly) in the same %%sql cell.
  • ⏱️ Non-Blocking --live Dashboards: Auto-refresh queries on a timer without blocking the Jupyter kernel. Includes interactive Play/Pause/Stop widget controls.
  • 🔌 Named Connection Registry: Connect to multiple databases/warehouses and switch between them using -c <name> or esje.use().
  • 🗣️ MySQL-Style Dialect Translation: Use familiar SHOW DATABASES, SHOW TABLES, DESCRIBE table commands — esje auto-translates them to BigQuery's INFORMATION_SCHEMA queries.
  • 🛡️ Clean Exception Handling: Friendly, concise error messages without distracting multi-page Python tracebacks.

📦 Installation

pip install esje

For Google BigQuery support (includes browser login):

pip install "esje[bigquery]"

For high-performance PyArrow acceleration:

pip install "esje[pyarrow,bigquery]"

🚀 Quickstart

1. Load the Extension

%load_ext esje

2. Connect to MySQL

import esje

# Prompts securely for any missing credentials
conn = esje.connect_mysql()

3. Connect to Google BigQuery

Opens your browser for Google Sign-In. No JSON key file needed.

import esje

conn = esje.connect_bigquery(
    name="bq",
    project="my-gcp-project",
    auth_method="browser"       # opens browser → sign in → done!
)

In Jupyter, auth_method="browser" is the default when no credentials are configured. Just call connect_bigquery(project="my-gcp-project").

🖥 Option B — Application Default Credentials (ADC)

Uses your existing gcloud auth application-default login session.

conn = esje.connect_bigquery(
    name="bq",
    project="my-gcp-project",
    auth_method="adc"
)

🔑 Option C — Service Account Key File

conn = esje.connect_bigquery(
    name="bq",
    project="my-gcp-project",
    credentials_path="/path/to/service_account.json",
    auth_method="service_account"
)

Auth method auto-detection:

Condition Method chosen
credentials_path is set service_account
Running interactively in Jupyter browser
Non-interactive / CI environment adc

💡 Usage Examples

Line Magic (%sql)

%sql SELECT * FROM users LIMIT 5

# With named connection
%sql -c bq SELECT country, SUM(revenue) FROM `project.dataset.orders` GROUP BY country

Cell Magic (%%sql)

%%sql -c bq -o sales_summary
SELECT
    category,
    COUNT(*)        AS total_orders,
    SUM(revenue)    AS total_revenue
FROM `my-gcp-project.my_database.sales`
WHERE sale_date >= '2024-01-01'
GROUP BY category
ORDER BY total_revenue DESC

Create Dataset & Table

%%sql -c bq
CREATE SCHEMA IF NOT EXISTS `my-gcp-project.my_database`
OPTIONS (description = "My first esje dataset")
%%sql -c bq
CREATE TABLE IF NOT EXISTS `my-gcp-project.my_database.sales` (
    id          INT64,
    product     STRING,
    category    STRING,
    quantity    INT64,
    revenue     FLOAT64,
    sale_date   DATE
)

🗣️ MySQL-Style Shorthand Commands

esje auto-translates familiar MySQL commands to BigQuery equivalents:

%%sql -c bq
SHOW DATABASES          -- lists all datasets in your project

%%sql -c bq
SHOW TABLES             -- lists all tables across datasets

%%sql -c bq
SHOW TABLES IN my_database   -- tables in a specific dataset

%%sql -c bq
DESCRIBE my_database.sales   -- columns + data types of a table

SQL + Python in One Cell

Combine SQL data extraction with immediate visualization. The result DataFrame is automatically available as df:

%%sql -c bq
SELECT category, SUM(revenue) AS total_revenue
FROM `my-gcp-project.my_database.sales`
GROUP BY category;

import matplotlib.pyplot as plt

df.plot(x='category', y='total_revenue', kind='bar',
        title='Revenue by Category', color='steelblue', figsize=(8, 4))
plt.tight_layout()
plt.show()

🔄 Non-Blocking Live Dashboards (--live)

Auto-refresh dashboards without blocking the Jupyter kernel:

%%sql -c bq --live 5
SELECT category, SUM(revenue) AS total_revenue
FROM `my-gcp-project.my_database.sales`
GROUP BY category;

import matplotlib.pyplot as plt

df.plot(x='category', y='total_revenue', kind='bar',
        title='Real-Time Revenue Dashboard', color='teal', figsize=(8, 4))
plt.tight_layout()
plt.show()

Each live widget includes interactive ▶️ Play / ⏸ Pause / ⏹ Stop buttons.

esje.pause_live()      # Pause all active live widgets
esje.resume_live()     # Resume all
esje.stop_all_live()   # Stop all background widgets

🔑 Credential Resolution Order

Priority Source
1 Explicit parameters passed to connect_bigquery(...)
2 .env file (ESJE_BIGQUERY_PROJECT, ESJE_BIGQUERY_AUTH_METHOD, etc.)
3 OS environment variables (GCP_PROJECT, GOOGLE_APPLICATION_CREDENTIALS, etc.)
4 Interactive browser login or getpass prompt

BigQuery environment variables:

Variable Purpose
ESJE_BIGQUERY_PROJECT / GCP_PROJECT GCP Project ID
ESJE_BIGQUERY_AUTH_METHOD browser, adc, or service_account
ESJE_BIGQUERY_CREDENTIALS_PATH / GOOGLE_APPLICATION_CREDENTIALS Service account JSON path
ESJE_BIGQUERY_DATASET Default dataset
ESJE_BIGQUERY_LOCATION Dataset location (e.g. US)

⚙️ Configuration Options

import esje

esje.config.max_display_rows = 50      # Max rows shown in HTML output (default: 100)
esje.config.verbose_errors = True      # Show full tracebacks (default: False)
esje.config.use_pyarrow = True         # Enable PyArrow backend (default: auto-detect)
esje.config.auto_commit = True         # Auto-commit DML statements (default: True)

🔌 Connection Management

esje.connections()       # List all active connections as a DataFrame
esje.use("bq")           # Set default connection for %sql
esje.close("bq")         # Close a specific connection
esje.close_all()         # Close all connections + stop live widgets

🔮 Roadmap

🌐 Universal Database Connectivity

  • Relational: PostgreSQL, SQLite, Oracle, MS SQL Server, CockroachDB
  • Big Data & Warehouses: Apache Hive, Trino/Presto, Spark SQL, Databricks, Snowflake, Amazon Redshift, ClickHouse
  • Embedded Engines: DuckDB, Polars, direct Parquet/Feather querying

🤖 AI Companion (--ai)

  • Natural language to SQL: %sql --ai "Show top revenue categories in 2026"
  • AI self-healing queries and schema-aware error fixes
  • Automated chart type selection via LLMs (OpenAI, Gemini, Ollama)

📊 Advanced Dashboarding

  • Multi-chart grid canvas in single cells
  • Webhook / Slack alerting on metric thresholds
  • Enterprise vault integration (AWS Secrets Manager, HashiCorp Vault, Azure Key Vault)

📄 License

Distributed under the MIT License.

Release files for esje 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for esje 0.3.2
File Size Uploaded
esje-0.3.2.tar.gz 28.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for esje 0.3.2
File Interpreter ABI Platform
esje-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.6 kB

Release files / esje-0.3.2.tar.gz

Download URL esje-0.3.2.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
adbf99920b82dfdd2ba3190f275601f44d587620223990e1fa5c7a0d154e7357
BLAKE2b-256 checksum
How to use checksums
74c555d5f9b890584afffcae237769aab9127edb7579538c073f28fb2f17822e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / esje-0.3.2-py3-none-any.whl

Download URL esje-0.3.2-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a1a9570611b46da656a5ba042bab3cbc47dbc538fc964db6d9a2d579eafdc06
BLAKE2b-256 checksum
How to use checksums
af7cfbadd577ebda36ae5262728b84b3035e0670074c79b577be64297a31e6dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page