Skip to main content

SQLsaber - Open-source agentic SQL assistant

Project description

SQLsaber

SQLsaber is an open-source agentic SQL assistant. Think Claude Code but for SQL.

demo

Stop fighting your database.

Ask your questions in natural language and sqlsaber will gather the right context automatically and answer your query by writing SQL and analyzing the results.

Table of Contents

Features

  • Automatic database schema introspection

  • Safe query execution (read-only by default)

  • Memory management

  • Interactive REPL mode

  • Conversation threads (store, display, and resume conversations)

  • Support for PostgreSQL, MySQL, SQLite, DuckDB, and CSVs

  • Extended thinking mode for select models (Anthropic, OpenAI, Google, Groq)

  • Beautiful formatted output

Installation

uv

uv tool install sqlsaber

pipx

pipx install sqlsaber

brew

brew install uv
uv tool install sqlsaber

Configuration

Database Connection

Set your database connection URL:

saber db add DB_NAME

This will ask you some questions about your database connection

AI Model Configuration

SQLSaber uses Sonnet-4 by default. You can change it using:

saber models set

# for more model settings run:
saber models --help

Memory Management

You can add specific context about your database to the model using the memory feature. This is similar to how you add memory/context in Claude Code.

saber memory add 'always convert dates to string for easier formating'

View all memories

saber memory list

You can also add memories in an interactive query session by starting with the # sign

Extended Thinking Mode

For complex queries that require deeper reasoning, sqlsaber supports extended thinking mode. When enabled, you will see the model's reasoning process as it generates SQL queries and arrives at conclusions.

Enable/disable via CLI flags:

# Enable thinking for a single query
saber --thinking "analyze sales trends across regions"

# Disable thinking for a single query
saber --no-thinking "show me all users"

Toggle in interactive mode:

# In interactive mode, use slash commands
/thinking on   # Enable thinking
/thinking off  # Disable thinking

Configure default setting:

Thinking is disabled by default. To change the default, edit your config file at ~/.config/sqlsaber/model_config.json:

{
  "model": "anthropic:claude-sonnet-4-20250514",
  "thinking_enabled": true
}

Usage

Interactive Mode

Start an interactive session:

saber

You can also add memories in an interactive session by starting your message with the # sign

Single Query

Execute a single natural language query:

saber "show me all users created this month"

You can also pipe queries from stdin:

echo "show me all users created this month" | saber
cat query.txt | saber

Resume Past Conversation

Continue a previous conversation thread:

saber threads resume THREAD_ID

Database Selection

Use a specific database connection:

# Interactive mode with specific database
saber -d mydb

# Single query with specific database
saber -d mydb "count all orders"

# You can also pass a connection string
saber -d "postgresql://user:password@localhost:5432/mydb" "count all orders"
saber -d "duckdb:///path/to/data.duckdb" "top customers"

Examples

# Start interactive mode
saber

# Non-interactive mode
saber "show me orders with customer details for this week"

saber "which products had the highest sales growth last quarter?"

How It Works

SQLsaber uses a multi-step agentic process to gather the right context and execute SQL queries to answer your questions:

🔍 Discovery Phase

  1. List Tables Tool: Quickly discovers available tables with row counts
  2. Pattern Matching: Identifies relevant tables based on your query

📋 Schema Analysis

  1. Smart Schema Introspection: Analyzes only the specific table structures needed for your query

⚡ Execution Phase

  1. SQL Generation: Creates optimized SQL queries based on natural language input
  2. Safe Execution: Runs read-only queries with built-in protections against destructive operations
  3. Result Formatting: Presents results with explanations in tables

Contributing

If you like the project, starring the repo is a great way to show your support!

Other contributions are welcome! Please feel free to open an issue to discuss your ideas or report bugs.

License

This project is licensed under Apache-2.0 License - see the LICENSE file for details.

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

sqlsaber-0.41.0.tar.gz (6.3 MB view details)

Uploaded Source

Built Distribution

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

sqlsaber-0.41.0-py3-none-any.whl (118.9 kB view details)

Uploaded Python 3

File details

Details for the file sqlsaber-0.41.0.tar.gz.

File metadata

  • Download URL: sqlsaber-0.41.0.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sqlsaber-0.41.0.tar.gz
Algorithm Hash digest
SHA256 6cdca21fca6af73ca9a37b0df10cbea982de81d1a4f3dedb467f186514b68286
MD5 f31ab5ec06dcc75c25d27a16572274c5
BLAKE2b-256 75f58d4930720a36ec7d1146cac1f8f78d8b53b20a90acf20fcf2249076ea667

See more details on using hashes here.

File details

Details for the file sqlsaber-0.41.0-py3-none-any.whl.

File metadata

  • Download URL: sqlsaber-0.41.0-py3-none-any.whl
  • Upload date:
  • Size: 118.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sqlsaber-0.41.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b4c6300329b3a68ba4e06da2153982b5ed055c3d364c1c18263a57e21176ee2
MD5 efc600e667d9780f53c1fe29d36ac4af
BLAKE2b-256 9c9589b74bb27f2d28cca9d50a70dc3600f281f14320667dc6cbc73782f3f9b5

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