Skip to main content

An AI-powered tool that can be called from inside psql to ask natural language questions about your PostgreSQL database with access to the database context and PostgreSQL documentation.

Project description

psql-chat

psql-chat lets you ask your PostgreSQL database questions in natural language. The tool translates your request into SQL or psql shell commands, gives you a syntax-highlighted explanation, and can optionally execute the command after confirmation.

Features

  • Natural language to SQL – Converts plain-language prompts into PostgreSQL commands.
  • Database-aware – Gathers schema context automatically (tables, columns, relationships) unless disabled with --no-context.
  • Documentation lookup – Fetches relevant PostgreSQL docs on demand through Context7.
  • Safety first – Warns when a query will modify data and asks for confirmation before executing.
  • Rich terminal output – Uses Rich for colored, syntax-highlighted explanations.
  • Flexible usage – Explain-only (default), execute with --execute, or skip docs with --no-docs for faster responses.

Quick Start

uvx psql-chat "how do I list all users?"
uvx psql-chat --dsn "postgresql://user:pass@host:5432/db" "show top 10 customers"
uvx psql-chat "delete inactive users" --execute  # confirmation required

You can also call it from inside psql:

\! psql-chat "count orders by month"
\! psql-chat --no-docs "list tables"

Requirements

  • Python 3.11+
  • A PostgreSQL connection (either via environment variables/.pgpass or --dsn)
  • An OpenAI API key available as the OPENAI_API_KEY environment variable
  • uv package manager (for uvx) or another way to install/run the package

Installation

uv pip install psql-chat

On Windows the repository includes a setup.ps1 helper script that installs dependencies and configures a shell alias so psql-chat is available in psql.

Usage Options

psql-chat [OPTIONS] "your request"

Options:
  --dsn TEXT          PostgreSQL connection URI.
  --no-context        Skip schema discovery for faster responses.
  --no-docs           Skip fetching PostgreSQL documentation.
  -e, --execute       Execute the generated command after confirmation.
  --verbose           Show gathered schema context for debugging.
  --version           Show the program version and exit.

License

This project is released under the PostgreSQL License (MIT-style).

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

psql_chat-0.3.1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

psql_chat-0.3.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file psql_chat-0.3.1.tar.gz.

File metadata

  • Download URL: psql_chat-0.3.1.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for psql_chat-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9dd46dff5bd01686ea12a519ba501bee5b49795ad6714b2f336f3069c5b0c5e2
MD5 5e28387b6c568c3130066429bcc99a84
BLAKE2b-256 476fe4366fed9466e17df6eef7afb0046e75474879c08000786f7794b83afeb9

See more details on using hashes here.

File details

Details for the file psql_chat-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: psql_chat-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for psql_chat-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2af592d4efc9bb8168b530912e2dbbdd0f5648ee6b2d360865fc4f621b6787c
MD5 7b27018597a261e23bcc0a5f9b0d21dc
BLAKE2b-256 8d9f323c9f3ee6dbbc75d7f9c90394d2b0eea807097c5a27e7270b82ad5c5a79

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