Query Companion: a CLI to query Postgres databases in natural language.
Project description
qcp — Query Companion
Query your Postgres database in plain English, right from the terminal.
$ qcp query "what were the top 5 customers by revenue last month?"
Reading schema...
Generating SQL...
SELECT customer_name, SUM(amount) AS revenue
FROM orders
WHERE order_date >= date_trunc('month', now()) - interval '1 month'
AND order_date < date_trunc('month', now())
GROUP BY customer_name
ORDER BY revenue DESC
LIMIT 5
customer_name revenue
-------------- -------
Acme Corp 48210.50
Globex Inc 39120.00
...
(5 rows)
qcp uses a LangChain database agent powered by Google Gemini 2.5 Flash to
translate your question into a read-only SQL query, run it, print the exact
results, and explain the answer in plain language.
Features
- 🗣️ Ask questions in natural language, get SQL + results
- 🔒 Read-only by default — only
SELECT/WITHstatements are executed - 💡
qcp insights— AI-generated analytics suggestions for your schema - 🧠 Local schema memory with automatic 24-hour refresh
- 🔑 Bring your own Gemini API key (free tier available)
- 🪶 Minimal footprint — single CLI, no servers or daemons
Install
QCP requires Python 3.14 or newer.
macOS / Linux (curl)
curl -fsSL https://raw.githubusercontent.com/Moduna-AI/qcp-cli/main/scripts/install.sh | bash
macOS (Homebrew)
brew tap Moduna-AI/qcp-cli
brew install qcp
Windows (PowerShell)
irm https://raw.githubusercontent.com/Moduna-AI/qcp-cli/main/scripts/install.ps1 | iex
Via pip (any platform)
pip install qcp
Quickstart
# 1. Connect a Postgres database
qcp init
# 2. Add your Gemini API key (https://aistudio.google.com/apikey)
qcp auth
# 3. Ask away
qcp query "how many new signups did we get this week?"
# Or get general insights about your data
qcp insights
Running qcp query or qcp insights without a configured database raises a
clear error and tells you to run qcp init first.
Configuration
qcp stores config at ~/.qcp/config.json (override with QCP_HOME).
Validated schema metadata is cached separately at ~/.qcp/schema.json; it
never contains credentials or query result rows.
You can also use environment variables instead of (or to override) the
config file:
| Variable | Purpose |
|---|---|
QCP_DATABASE_URL |
Postgres connection string |
GEMINI_API_KEY |
Gemini API key |
Check current configuration any time with:
qcp status
Commands
| Command | Description |
|---|---|
qcp init |
Connect a Postgres database |
qcp auth |
Add/remove your Gemini API key |
qcp query "<question>" |
Ask a question, get SQL + results |
qcp insights |
Get AI-generated analytics suggestions |
qcp status |
Show current configuration |
Useful flags on qcp query:
--dry-run— print the generated SQL without executing it--no-show-sql— only print results, hide the SQL
Safety
qcp only executes one SELECT/WITH statement. Validation is backed by a
PostgreSQL read-only transaction, and there is no write override. Always review
generated SQL (shown by default), especially on production databases. A
read-only database role remains recommended as an additional boundary.
Agent tools
The LangChain agent has four narrow tools: lookup_schema, schema_memory,
execute_read_query, and analyze_insights. Schema data is reused for 24
hours, then refreshed automatically. An undefined table, column, or schema
invalidates the cache and permits one refresh-and-retry cycle.
Development
git clone https://github.com/Moduna-AI/qcp-cli
cd qcp
uv sync --extra dev
uv run pytest
Install the Git hook once with uv run pre-commit install. Use
uv run <command> for project commands; uvx creates an isolated environment
without QCP installed.
Clean install / clean build
A Makefile (plus equivalent standalone shell scripts) is included so you
never get bitten by stale venvs or cached build artifacts:
| Task | Make | Script |
|---|---|---|
| Wipe venv/dist/caches | make clean |
./scripts/clean.sh |
| Fresh editable install | make install |
— |
| Fresh install + test deps | make dev |
— |
| Clean build (sdist + wheel) | make build |
./scripts/build.sh |
| Clean install, then build | make rebuild |
— |
| Run tests | make test |
— |
| Run the CLI from venv | make run ARGS="status" |
— |
| Run Ruff checks | make lint |
— |
make build / ./scripts/build.sh always wipe the tree first, so dist/
is never tainted by a previous build. Both are safe to re-run anytime.
Roadmap (post-MVP)
- Additional LLM providers (OpenAI, Claude, local models)
- MySQL / SQLite support
- Query history and caching
- Saved queries / scheduled reports
License
MIT — see LICENSE.
Contributions welcome! Please open an issue or PR.
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 qcp_cli-0.1.7.tar.gz.
File metadata
- Download URL: qcp_cli-0.1.7.tar.gz
- Upload date:
- Size: 81.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97c5aadf0abca0815bbf0cc07fabb43b1203fa5fc17f5d1e4bdacd9b7fed1be9
|
|
| MD5 |
55d09fe2ff21b02781cd9be0987ecf85
|
|
| BLAKE2b-256 |
0db00f6f21d8f5601d2ce4d9f7f77f4bb515ea5d7a83b6a513a170490035f85c
|
Provenance
The following attestation bundles were made for qcp_cli-0.1.7.tar.gz:
Publisher:
release.yml on Moduna-AI/qcp-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qcp_cli-0.1.7.tar.gz -
Subject digest:
97c5aadf0abca0815bbf0cc07fabb43b1203fa5fc17f5d1e4bdacd9b7fed1be9 - Sigstore transparency entry: 1899238673
- Sigstore integration time:
-
Permalink:
Moduna-AI/qcp-cli@c775b483be382ed0b9b908c626fb4676378fc446 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/Moduna-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c775b483be382ed0b9b908c626fb4676378fc446 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qcp_cli-0.1.7-py3-none-any.whl.
File metadata
- Download URL: qcp_cli-0.1.7-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c60d87d2edd86145fe3d1eb539ff9d884d4d64d7a8c137991b540644159f7c8d
|
|
| MD5 |
93f377b06a4d423fb30be76eeff793ce
|
|
| BLAKE2b-256 |
f2990773e3f9df48d96193afb9c71c9fa24adb7e4e14a840ef15e476e103266f
|
Provenance
The following attestation bundles were made for qcp_cli-0.1.7-py3-none-any.whl:
Publisher:
release.yml on Moduna-AI/qcp-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qcp_cli-0.1.7-py3-none-any.whl -
Subject digest:
c60d87d2edd86145fe3d1eb539ff9d884d4d64d7a8c137991b540644159f7c8d - Sigstore transparency entry: 1899238811
- Sigstore integration time:
-
Permalink:
Moduna-AI/qcp-cli@c775b483be382ed0b9b908c626fb4676378fc446 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/Moduna-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c775b483be382ed0b9b908c626fb4676378fc446 -
Trigger Event:
push
-
Statement type: