Skip to main content

CLI tool for managing usql database connections with alias management and Tab auto-completion

Project description

usqlh

A CLI tool for managing usql database connections with alias management and Tab auto-completion.

Why usqlh?

usql is a universal command-line interface for SQL databases, but it requires you to remember or type full connection URLs every time. usqlh solves this by:

  • Storing connections with memorable aliases
  • Providing Tab auto-completion for alias names
  • Offering interactive connection setup with validation

Installation

# Install from PyPI
pip install usqlh

# Or install from source
git clone https://github.com/aki-colt/usqlh.git
cd usqlh
pip install -e .

Prerequisites

  • Python 3.8+
  • usql installed and available in PATH

Quick Start

# Add a new connection
usqlh add mydb
# Follow the interactive prompts to configure

# Connect to database
usqlh connect  # Tab to select from saved connections
# Or directly:
usqlh mydb

# List all saved connections
usqlh list

Usage

Command Description
usqlh add [alias] Add/update a connection (interactive)
usqlh edit [alias] Edit existing connection (Tab to complete)
usqlh remove [alias] Remove a connection (Tab to complete)
usqlh rename <old> <new> Rename an alias
usqlh list [pattern] List connections (optional filter)
usqlh connect [alias] Connect with Tab completion
usqlh c [alias] Short alias for connect
usqlh <alias> [args] Connect directly, pass extra args to usql

Auto-completion

Press Tab when prompted for an alias to:

  • Show all available aliases (empty input)
  • Complete partial input (e.g., mymydb)

Works in all shells (bash, zsh, sh) without additional configuration.

Supported Databases

All databases supported by usql:

Database Schemes
PostgreSQL postgres, postgresql, pg
MySQL mysql, mysql2
SQLite sqlite, sqlite3
SQL Server mssql, sqlserver
Oracle oracle
CockroachDB cockroachdb
Redis redis
MongoDB mongodb

Configuration

Connections are stored in ~/.usqldb:

mydb:postgres://user:pass@localhost:5432/mydb
prod:mysql://admin:secret@db.example.com:3306/app
local:sqlite3:///path/to/db.sqlite

Architecture

usqlh/
├── __init__.py     # Entry point
├── cli.py          # Command routing and argument parsing
├── core.py         # Connection URL building/parsing, usql execution
├── config.py       # ~/.usqldb file management
├── completer.py    # readline-based Tab completion
└── models.py       # Database type definitions

Key Design Decisions

  1. Zero runtime dependencies - Uses only Python standard library (readline, argparse, urllib)
  2. readline for completion - Works across all terminal emulators without shell-specific config
  3. Simple file format - Plain text alias:url for easy manual editing and version control
  4. Thin wrapper - Delegates actual database operations to usql via execvp

Development

# Create virtual environment with uv
uv venv
source .venv/bin/activate

# Install with dev dependencies
uv pip install -e ".[dev]"

# Run linter
ruff check usqlh/

# Format code
ruff format usqlh/

# Type check
mypy usqlh/

License

MIT

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

usqlh-0.2.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

usqlh-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file usqlh-0.2.0.tar.gz.

File metadata

  • Download URL: usqlh-0.2.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for usqlh-0.2.0.tar.gz
Algorithm Hash digest
SHA256 05b5530942848b85ca9ddcf0b146a3be66b912ff230b3d016359e608ae547d64
MD5 e319881faedce86373b7ac1b66a66379
BLAKE2b-256 9d7ec44d15dcb11a282dbbbb46f337d675b832279a1a02b88a1288a4398fad56

See more details on using hashes here.

File details

Details for the file usqlh-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: usqlh-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for usqlh-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b3a15723088281b67cbf314756addb8864828d39e5192ba5255342805307016
MD5 1c81040dfa08b3c69f4f9cd8f5f3601f
BLAKE2b-256 394e22349114549ac42caafbfd5855923ae08637f8baaafc28c7e90d95ec612a

See more details on using hashes here.

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