Skip to main content

Agent-friendly ClickHouse query CLI — JSON-first, read-only by default, semantic exit codes.

Project description

chsql

English · 简体中文

Agent-friendly ClickHouse query CLI — JSON-first, read-only by default, semantic exit codes. A thin wrapper over clickhouse-driver / clickhouse-connect with zero third-party CLI framework (stdlib argparse). Batteries included: native + HTTP transports and OS-keyring password storage all work out of the box (~8 MB installed). Built for LLM agents to call over the shell instead of standing up an MCP server.

Install

uv tool install chsql     # recommended (puts chsql on your PATH)
# or
pipx install chsql

Then install the bundled agent skill (cross-agent path ~/.agents/skills):

chsql skill install

Use

chsql databases
chsql tables system --like '%part%'
chsql describe system.parts
chsql query "SELECT count() FROM system.tables"

Default output is JSONEachRow (NDJSON). Switch with --format json|table|csv|tsv. Results are capped at 100k rows by default (--max-rows N, --max-rows 0 to disable).

Connection — one URL

A connection is a single URL:

clickhouse://user:password@host:port/database?secure=1

chsql login stores it in the OS keyring (the password never touches a config file) — then everything just works with no flags:

chsql login 'clickhouse://me:pw@ch.example.com:443?secure=1'   # paste once
chsql databases                                                # zero-config
chsql login --show     # print the stored URL (password masked)
chsql logout           # remove it

Resolution order: --url flag > $CHSQL_URL env > the stored login. Individual --host/--port/--user/--password/--secure/--protocol/--database flags override fields for one-off use:

# Public read-only playground — no login needed
chsql --host play.clickhouse.com --user explorer --secure databases

Transport

Protocol Ports Driver When
native (default) 9000 / 9440 clickhouse-driver direct TCP access
http 8123 / 8443 / 443 clickhouse-connect HTTPS reverse-proxied servers

--protocol auto (default) picks http for ports 443/8123/8443, else native.

Agent contract

Aspect Behavior
Output data → stdout (JSONEachRow by default); errors → stderr as {"error","code"}
Exit codes 0 ok · 1 query error · 2 connection error · 3 write/DDL blocked
Safety read-only by default; --write for DML, --allow-ddl for DDL; multi-statement aware
Limits results capped at --max-rows (default 100k); truncation noted on stderr
Params --param k=v bound as %(k)s (numeric values passed unquoted)

Commands

  • chsql query "<sql>" — run SQL (reads stdin if no arg). Read-only unless --write/--allow-ddl.
  • chsql databases — list databases.
  • chsql tables [db] --like ... --not-like ... — list tables with engine and counts.
  • chsql describe <table|db.table> — list columns (name, type, default, comment).
  • chsql login [URL] | logout | login --show — manage the stored connection.
  • chsql skill install [--path DIR] — install the bundled agent skill.
  • chsql --version

Develop

pip install -e '.[dev]'
pytest

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

chsql-0.4.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

chsql-0.4.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file chsql-0.4.0.tar.gz.

File metadata

  • Download URL: chsql-0.4.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chsql-0.4.0.tar.gz
Algorithm Hash digest
SHA256 578a46ebd59a208cac018d86f6efd3d1b7dd8256881bba0a597cb0eb35022c71
MD5 0b143cae6c1e17702627f600ddfe98a8
BLAKE2b-256 11f68cc9a21d3d8323eb177f672b6d0d7da73159620442052440457ad945300c

See more details on using hashes here.

Provenance

The following attestation bundles were made for chsql-0.4.0.tar.gz:

Publisher: release.yml on dengshu2/chsql

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

File details

Details for the file chsql-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: chsql-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chsql-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8171f1c1c4492d4e18df3a4adaf5446a69a343f71d6533cfe1f5be2e7bace5d4
MD5 0cd89dc453a797d1f43e422e8f655010
BLAKE2b-256 8436aec86b8dae8a39b203b8d521b9022819ce817f4a84aa8ee814a611439763

See more details on using hashes here.

Provenance

The following attestation bundles were made for chsql-0.4.0-py3-none-any.whl:

Publisher: release.yml on dengshu2/chsql

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