Skip to main content

A command-line tool for managing database schemas and generating SQL queries using natural language.

Project description

tabletalk

tabletalk is a command-line interface (CLI) tool designed to let you "talk" to your databases using natural language. Unlike heavier frameworks like Langchain—an 18-wheeler in comparison—tabletalk is a sleek sedan, built for simplicity and ease of use. With tabletalk, you can define specific "contexts" based on relationships in your data, then query that data conversationally, either by generating SQL or asking questions directly. It connects to your existing databases—BigQuery, SQLite, MySQL, or Postgres—pulls schemas based on your defined contexts, and leverages large language models (LLMs) from OpenAI and Anthropic to chat with your data effectively.

Features

  • Database Support: Connect to BigQuery, SQLite, MySQL, and Postgres.
  • Custom Contexts: Define relationships in your data to create focused querying scenarios.
  • LLM Integration: Use OpenAI or Anthropic models to generate SQL or answer questions.
  • Natural Language Queries: Ask questions about your data in plain English, with SQL generated automatically.
  • Local Execution: Run generated SQL locally against your database.

Installation

Install tabletalk via pip:

pip install tabletalk

Configuration

Tabletalk relies on a configuration file named tabletalk.yaml to set up your database and LLM preferences. This file includes:

  • Provider: Details for connecting to your database.
  • LLM: Settings for the language model, such as provider, API key, and model specifics.
  • Contexts: Path to a directory containing context definitions.
  • Output: Directory where manifest files (schema data) are stored.

Note: For security, set API keys as environment variables (e.g., export ANTHROPIC_API_KEY="your-key-here").

Defining Contexts

Contexts are defined in separate YAML files within the contexts directory. Each context specifies a subset of your database—datasets and tables—relevant to a particular querying scenario.

  • Provider: Details for connecting to your database.
  • LLM: Settings for the language model, such as provider, API key, and model specifics.
  • Contexts: Path to a directory containing context definitions.
  • Output: Directory where manifest files (schema data) are stored.

Note: For security, set API keys as environment variables (e.g., export ANTHROPIC_API_KEY="your-key-here").

Here’s an example tabletalk.yaml:

provider:
  type: mysql
  host: localhost
  user: root
  password: ${MYSQL_PASSWORD}
  database: test_store

llm:
  provider: anthropic
  api_key: ${ANTHROPIC_API_KEY}
  model: claude-3-5-sonnet-20240620
  max_tokens: 500
  temperature: 0

contexts: contexts
output: manifest

Defining Contexts

Contexts are defined in separate YAML files within the contexts directory. Each context specifies a subset of your database—datasets and tables—relevant to a particular querying scenario.

Example context file contexts/sales_context.yaml:

name: sales_context
datasets:
  - name: test_store
    tables:
      - customers
      - orders

Usage

Tabletalk offers three core CLI commands:

tabletalk init

init: Sets up a new tabletalk project in your current directory, creating tabletalk.yaml, a contexts/ folder, and a manifest/ folder.

tabletalk apply

apply: Reads context definitions from the contexts directory, connects to your database, pulls the relevant schemas, and generates manifest files in the output directory (e.g., manifest/).

tabletalk query

query: Launches an interactive session where you select a manifest (representing a context) and ask questions in natural language. The LLM generates SQL queries based on your input.

Example Workflow

Let’s set up and query a simple sales database:

Initialize the Project:

tabletalk init

This creates the project structure:

project_folder/
├── tabletalk.yaml
├── contexts/
└── manifest/

Define a Context:

Create contexts/sales_context.yaml:

name: sales_context
datasets:
  - name: test_store
    tables:
      - customers
      - orders

Configure tabletalk.yaml:

name: sales_context
datasets:
  - name: test_store
    tables:
      - customers
      - orders

Apply the Schema:

tabletalk apply

This generates a manifest file (e.g., manifest/sales_context.json) with the schema for customers and orders.

Query Your Data:

tabletalk query

You’ll see a list of available manifests (e.g., 1. sales_context.json). Enter the number (e.g., 1) to select it. Ask a question like: "How many customers placed orders last month?" The LLM generates an SQL query, which you can then run locally against your database. Type exit to end the session.

Contributing

Want to help improve tabletalk? Fork the repository, make your changes, and submit a pull request. For major updates, please open an issue first to discuss your ideas.

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

tabletalk-0.1.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

tabletalk-0.1.1-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file tabletalk-0.1.1.tar.gz.

File metadata

  • Download URL: tabletalk-0.1.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tabletalk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c4c1c4fb6aa43429f739d7fb6899d41b1b39f4688372f8d9cc093d2eb3b83436
MD5 1d81b2baa252b3408e33a56ed097f983
BLAKE2b-256 bd1fcca8f6c9d745f85864d77839922ead76bcffd91d58eab1751a390bd0fc02

See more details on using hashes here.

File details

Details for the file tabletalk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tabletalk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tabletalk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b22c80d1fd5343a75e53fe70c005c5b836c80a8a3ad836c086dbb202220f9b8
MD5 f744156e0fa2a4de47aeb644175e9e5b
BLAKE2b-256 7387761d0e0e0603c4e647e8f34a196486008cbf8dda71b33f222021583352a4

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