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
usql-helper add mydb
# Follow the interactive prompts to configure

# Connect to the database
usql-helper connect  # Tab to select from saved connections
# Or directly:
usql-helper mydb

# List all saved connections
usql-helper list

Usage

Command Description
usql-helper add [alias] Add/update a connection (interactive)
usql-helper edit [alias] Edit existing connection (Tab to complete)
usql-helper remove [alias] Remove a connection (Tab to complete)
usql-helper rename <old> <new> Rename an alias
usql-helper list [pattern] List connections (optional filter)
usql-helper connect [alias] Connect with Tab completion
usql-helper c [alias] Short alias for connect
usql-helper <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.1.0.tar.gz (12.3 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.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for usqlh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 666b1b9c152045e1c091572322f33197958c2bdd44f0c454b5d7e7a9978a87ca
MD5 c046303e9ebb0e7543ab3cf54b7b7dec
BLAKE2b-256 c9dc1c9e34eec9084e9eb80f8f7c1cdcb02365f251c9df9b05af38426e0aec3b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: usqlh-0.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6cbd1409a5aa27a2553b431d971105a62fa8e67d1a010593941fbc20b3eb3bb
MD5 64b11c0b977d8c8bd8234a32e1c61826
BLAKE2b-256 5e2ae3edae1d0c6c38c6c1f5bd0b0cbe33aff36809593bbc1aaeb24953c608bb

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