A JupyterLab extension to complete db queries in jupyterlab notebooks
Project description
jl_db_comp
A JupyterLab extension that provides PostgreSQL table and column name autocompletion when typing SQL queries in notebooks and editors.
Features
- Smart SQL Detection: Automatically activates when SQL keywords (SELECT, FROM, JOIN, etc.) are detected
- PostgreSQL Integration: Queries table and column names from PostgreSQL databases
- Client-Side Caching: 5-minute TTL cache to minimize database calls
- Configurable: Database connection via environment variable or settings
- Schema Support: Query specific database schemas (defaults to 'public')
This extension is composed of a Python package named jl_db_comp
for the server extension and a NPM package named jl_db_comp
for the frontend extension.
Requirements
- JupyterLab >= 4.0.0
- PostgreSQL database
- Python >= 3.10
Install
To install the extension, execute:
pip install jl_db_comp
Configuration
Database Connection
There are two ways to configure your PostgreSQL database connection:
Option 1: Environment Variable (Recommended)
Set the POSTGRES_URL environment variable before starting JupyterLab:
export POSTGRES_URL="postgresql://user:password@localhost:5432/dbname"
jupyter lab
Option 2: JupyterLab Settings
- Open JupyterLab Settings (Settings โ Settings Editor)
- Search for "PostgreSQL Database Completer"
- Configure:
- Database URL: PostgreSQL connection string
- Schema: Database schema to query (default: 'public')
- Enabled: Toggle completions on/off
Connection String Format
postgresql://[user[:password]@][host][:port][/dbname]
Examples:
# Local database
postgresql://postgres:example@localhost:5432/ehrexample
# Remote database with SSL
postgresql://user:pass@db.example.com:5432/mydb?sslmode=require
Usage
Table Name Completion
Type SQL and press Tab or Ctrl+Space to see table names:
SELECT * FROM pat<Tab>
Completions will show:
- ๐ patients
- ๐ patient_visits
- ๐ patient_records
Column Name Completion (After Table Name)
After typing a table name followed by a dot, you'll see only the columns from that table:
SELECT patients.<Tab>
Completions will show columns from 'patients' table:
- ๐ patient_id (patients)
- ๐ patient_name (patients)
- ๐ date_of_birth (patients)
-- Works with table aliases too:
SELECT p.<Tab>
FROM patients p
Completions will show columns from 'p' (if it's a known table)
Smart Activation
Autocomplete activates when SQL keywords are detected:
- SELECT, FROM, JOIN, WHERE
- INSERT, UPDATE, DELETE
- GROUP BY, ORDER BY, etc.
Schema-Aware Completion
Access tables and columns from different schemas:
-- List tables from a specific schema
SELECT * FROM custom_schema.<Tab>
Completions will show tables and views from 'custom_schema':
- ๐ users
- ๐ products
- ๐๏ธ active_users (view)
-- Access columns from schema-qualified table
SELECT custom_schema.users.<Tab>
Completions will show columns from custom_schema.users:
- ๐ user_id (users)
- ๐ username (users)
- ๐ email (users)
JSONB Key Completion
For JSONB columns, get autocomplete for JSON object keys after typing -> or ->>:
-- First-level JSONB keys
SELECT metadata-><Tab>
FROM patients
Completions will show keys from the 'metadata' JSONB column:
- ๐ allergies
- ๐ medications
- ๐ diagnosis
-- Nested JSONB keys
SELECT metadata->>'diagnosis'-><Tab>
FROM patients
Completions will show nested keys under 'diagnosis':
- ๐ code
- ๐ description
- ๐ date
How it works:
- Extension queries actual table data to extract unique JSONB keys
- Supports nested paths (e.g.,
column->>'key1'->>'key2'->) - Samples up to 1000 rows for performance
- Works with table-qualified columns (e.g.,
patients.metadata->)
Complete Example
-- Step 1: Type table name and press Tab (default schema)
SELECT * FROM pat<Tab>
-- โ Suggests: patients, patient_visits
-- Step 2: After selecting "patients", type dot and press Tab
SELECT patients.<Tab>
-- โ Shows columns: patient_id, patient_name, etc.
-- Step 3: JSONB key completion
SELECT patients.metadata-><Tab>
-- โ Shows JSONB keys: allergies, medications, diagnosis
-- Step 4: Nested JSONB keys
SELECT patients.metadata->>'diagnosis'-><Tab>
-- โ Shows nested keys: code, description, date
-- Step 5: With different schemas
SELECT
public.patients.<Tab>,
custom_schema.users.<Tab>
FROM public.patients
JOIN custom_schema.users ON patients.user_id = users.user_id
-- โ "public.patients." shows patient columns
-- โ "custom_schema.users." shows user columns
-- Step 6: List tables from specific schema
SELECT * FROM custom_schema.<Tab>
-- โ Shows tables and views from custom_schema
Uninstall
To remove the extension, execute:
pip uninstall jl_db_comp
Troubleshoot
If you are seeing the frontend extension, but it is not working, check that the server extension is enabled:
jupyter server extension list
If the server extension is installed and enabled, but you are not seeing the frontend extension, check the frontend extension is installed:
jupyter labextension list
JSONB Autocompletion Not Working
If JSONB key completion works on one database but not another, check the server logs (terminal running jupyter lab) for diagnostic messages when triggering completion.
You can also call the diagnostics endpoint directly:
GET /jl-db-comp/jsonb-diagnostics?table=TABLE_NAME&column=COLUMN_NAME
This returns the JSONB type distribution and a recommendation. Common causes:
- All NULL values - The column has no data
- Arrays instead of objects - Keys can only be extracted from
{}objects, not[]arrays - Wrong schema - Add
&schema=your_schemaif not usingpublic
Contributing
Development install
Note: You will need NodeJS to build the extension package.
The jlpm command is JupyterLab's pinned version of
yarn that is installed with JupyterLab. You may use
yarn or npm in lieu of jlpm below.
# Clone the repo to your local environment
# Change directory to the jl_db_comp directory
# Set up a virtual environment and install package in development mode
python -m venv .venv
source .venv/bin/activate
pip install --editable ".[dev,test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jl_db_comp
# Rebuild extension Typescript source after making changes
# IMPORTANT: Unlike the steps above which are performed only once, do this step
# every time you make a change.
jlpm build
You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab
With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
By default, the jlpm build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
jupyter lab build --minimize=False
Development uninstall
# Server extension must be manually disabled in develop mode
jupyter server extension disable jl_db_comp
pip uninstall jl_db_comp
In development mode, you will also need to remove the symlink created by jupyter labextension develop
command. To find its location, you can run jupyter labextension list to figure out where the labextensions
folder is located. Then you can remove the symlink named jl_db_comp within that folder.
Contributing Features and Fixes
This project uses a pull request workflow for all changes. This enables automated changelog generation and streamlined releases.
Development Workflow
1. Create a feature branch:
# For new features
git checkout -b feature/descriptive-name
# For bug fixes
git checkout -b fix/bug-description
# For documentation updates
git checkout -b docs/what-you-changed
2. Make your changes:
- Write code following the guidelines in
AGENTS.md/CLAUDE.md - Add tests for new functionality
- Update documentation as needed
- Run tests locally:
pytest -vv -r ap --cov jl_db_comp - Format code:
jlpm run lint
3. Commit and push:
git add .
git commit -m "Brief description of changes"
git push origin feature/descriptive-name
4. Create a Pull Request:
-
Click "New pull request"
-
Select your feature branch
-
Write a clear PR title - this becomes the changelog entry!
- โ Good: "Add support for MySQL databases"
- โ Good: "Fix JSONB key completion for nested objects"
- โ Bad: "updates", "fix bug", "changes"
-
Add a description explaining what changed and why
-
Add a label (REQUIRED for CI to pass):
enhancement- New featuresbug- Bug fixesdocumentation- Documentation updatesmaintenance- Maintenance tasks
Note: At least one label is required. The "Enforce PR label" CI check will fail if no label is set. You can add labels when creating the PR or afterwards from the PR sidebar.
-
Click "Create pull request"
5. Review and merge:
- CI checks must pass (build, tests, linting)
- Address any review feedback
- Once approved, merge the PR
- Delete the feature branch after merging
Automated Releases
Releases are created using GitHub Actions workflows:
Step 1: Prepare Release (Manual workflow)
- Go to Actions โ "Step 1: Prep Release" โ "Run workflow"
- Optionally specify version (e.g.,
0.2.0,patch,minor,major) - The workflow will:
- Bump the version
- Generate changelog from merged PRs since last release
- Create a draft GitHub release
Step 2: Publish Release (Manual workflow)
- Review the draft release
- Go to Actions โ "Step 2: Publish Release" โ "Run workflow"
- The workflow will:
- Publish to PyPI
- Publish to npm
- Make the GitHub release public
Note: Automated releases require repository secrets for PyPI (NPM_TOKEN) and GitHub App credentials. See RELEASE.md for setup details.
Testing the extension
Server tests
This extension is using Pytest for Python code testing.
Install test dependencies (needed only once):
pip install -e ".[test]"
# Each time you install the Python package, you need to restore the front-end extension link
jupyter labextension develop . --overwrite
To execute them, run:
pytest -vv -r ap --cov jl_db_comp
Frontend tests
This extension is using Jest for JavaScript code testing.
To execute them, execute:
jlpm
jlpm test
Integration tests
This extension uses Playwright for the integration tests (aka user level tests). More precisely, the JupyterLab helper Galata is used to handle testing the extension in JupyterLab.
More information are provided within the ui-tests README.
AI Coding Assistant Support
This project includes an AGENTS.md file with coding standards and best practices for JupyterLab extension development. The file follows the AGENTS.md standard for cross-tool compatibility.
Compatible AI Tools
AGENTS.md works with AI coding assistants that support the standard, including Cursor, GitHub Copilot, Windsurf, Aider, and others. For a current list of compatible tools, see the AGENTS.md standard.
This project also includes symlinks for tool-specific compatibility:
-
CLAUDE.mdโAGENTS.md(for Claude Code) -
GEMINI.mdโAGENTS.md(for Gemini Code Assist)
Other conventions you might encounter:
.cursorrules- Cursor's YAML/JSON format (Cursor also supports AGENTS.md natively)CONVENTIONS.md/CONTRIBUTING.md- For CodeConventions.ai and GitHub bots- Project-specific rules in JetBrains AI Assistant settings
All tool-specific files should be symlinks to AGENTS.md as the single source of truth.
What's Included
The AGENTS.md file provides guidance on:
- Code quality rules and file-scoped validation commands
- Naming conventions for packages, plugins, and files
- Coding standards (TypeScript, Python)
- Development workflow and debugging
- Backend-frontend integration patterns (
APIHandler,requestAPI(), routing) - Common pitfalls and how to avoid them
Customization
You can edit AGENTS.md to add project-specific conventions or adjust guidelines to match your team's practices. The file uses plain Markdown with Do/Don't patterns and references to actual project files.
Note: AGENTS.md is living documentation. Update it when you change conventions, add dependencies, or discover new patterns. Include AGENTS.md updates in commits that modify workflows or coding standards.
Packaging the extension
See RELEASE
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 jl_db_comp-0.1.9.tar.gz.
File metadata
- Download URL: jl_db_comp-0.1.9.tar.gz
- Upload date:
- Size: 191.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
569128ab8ba318a3d107c6603f98b7c0c719737eaa53d2739e064df359096cbe
|
|
| MD5 |
b0b84665cd2aaf7b9c17d89b2f641b39
|
|
| BLAKE2b-256 |
c1d439dcbc61597c1b398515707878dc5f6b5d22963c02b575de79441f054f95
|
Provenance
The following attestation bundles were made for jl_db_comp-0.1.9.tar.gz:
Publisher:
publish-release.yml on Ben-Herz/jl_db_completer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jl_db_comp-0.1.9.tar.gz -
Subject digest:
569128ab8ba318a3d107c6603f98b7c0c719737eaa53d2739e064df359096cbe - Sigstore transparency entry: 832760152
- Sigstore integration time:
-
Permalink:
Ben-Herz/jl_db_completer@dab25a47c626aa8c5c96c98c7624a190c74f8ac5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ben-Herz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-release.yml@dab25a47c626aa8c5c96c98c7624a190c74f8ac5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jl_db_comp-0.1.9-py3-none-any.whl.
File metadata
- Download URL: jl_db_comp-0.1.9-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2c211ac091353034840474bbd872a19868e7769dba83c90252373db104f04e0
|
|
| MD5 |
3a8f307ec2f640ecf077d73d7e4c25ee
|
|
| BLAKE2b-256 |
06f16e11a494d354d4920cc679dcc40ab4a3866cf761d33b6bdd4a3ecb845ceb
|
Provenance
The following attestation bundles were made for jl_db_comp-0.1.9-py3-none-any.whl:
Publisher:
publish-release.yml on Ben-Herz/jl_db_completer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jl_db_comp-0.1.9-py3-none-any.whl -
Subject digest:
e2c211ac091353034840474bbd872a19868e7769dba83c90252373db104f04e0 - Sigstore transparency entry: 832760154
- Sigstore integration time:
-
Permalink:
Ben-Herz/jl_db_completer@dab25a47c626aa8c5c96c98c7624a190c74f8ac5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ben-Herz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-release.yml@dab25a47c626aa8c5c96c98c7624a190c74f8ac5 -
Trigger Event:
workflow_dispatch
-
Statement type: