Skip to main content

A CLI tool that converts natural language queries into SQL and returns relevant tables using natural language.

Project description

๐Ÿค– TESH-Query

PyPI version Python Support License: MIT CI/CD Code style: black Imports: isort Sponsor

Transform natural language into SQL queries and get instant results โ€” No SQL knowledge required.

TESH-Query (Text to Executable SQL Handler) is an AI-powered CLI tool that bridges the gap between human language and database queries, making data accessible to everyone on your team.

Here is detailed documentation of configuration and usage information, see the Detailed Documentation.


โœจ See TESH-Query in Action!

Experience the power and simplicity of TESH-Query with a quick demonstration. See how easily you can get valuable data insights using just natural language.


๐ŸŽฏ What TESH-Query Does

Forget writing complex SQL queries. With TESH-Query, you simply ask for the data you need in plain English, and the tool handles the rest.

# Before: Crafting intricate SQL...
$ psql my_database -c "SELECT products.name, categories.category_name, orders.order_date FROM products JOIN order_items ON products.id = order_items.product_id JOIN orders ON order_items.order_id = orders.id JOIN categories ON products.category_id = categories.id WHERE categories.category_name = 'electronics' AND orders.order_date >= current_date - interval '1 month' ORDER BY orders.order_date DESC;"

# After: Just ask TESH-Query!
$ teshq query "Show me all high-value electronics orders from last month"

# Get instant, formatted results directly in your terminal:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Order ID   โ”‚ Product Name    โ”‚ Price     โ”‚ Order Date  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 12847      โ”‚ MacBook Pro M3  โ”‚ $2,499.00 โ”‚ 2025-04-15  โ”‚
โ”‚ 12923      โ”‚ OLED Monitor    โ”‚ $899.99   โ”‚ 2025-04-18  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ก Why Choose TESH-Query?

Accessing data shouldn't be a bottleneck. TESH-Query empowers your team by making database interaction intuitive and fast.

Key Benefits:

  • ๐Ÿš€ Democratize Data Access โ€” Enable everyone, regardless of technical background, to retrieve data independently.
  • โšก Boost Productivity โ€” Significantly reduce the time and effort required to get data insights.
  • ๐Ÿ›ก๏ธ Reduce Errors โ€” Minimize human errors associated with manual SQL writing.
  • ๐Ÿ” Focus on Analysis โ€” Spend more time understanding your data and less time wrestling with query syntax.

โœจ Key Features

  • ๐Ÿ’ฌ Intuitive Natural Language Interface โ€” Seamlessly interact with your database using everyday language.
  • ๐Ÿง  Intelligent SQL Generation โ€” Leverage the power of Google's Gemini AI (via Langchain) for accurate and context-aware SQL translation.
  • ๐Ÿ“Š Direct Data Display โ€” Get query results presented in clean, readable tables right in your terminal.
  • ๐Ÿ”Œ Broad Database Compatibility โ€” Connects natively with PostgreSQL, MySQL, and SQLite databases.
  • ๐Ÿ›ก๏ธ Schema-Aware Queries โ€” TESH-Query understands your database structure to generate highly relevant queries.
  • ๐ŸŽจ Modern CLI Experience โ€” Enjoy a responsive, user-friendly, and visually appealing interface thanks to Typer and Rich.
  • ๐Ÿ”’ Secure Credential Management โ€” Your sensitive database and API credentials are stored securely.
  • โš™๏ธ Customizable Configuration โ€” Easily set up and manage your database connections, AI models, and other settings.

โ–ถ๏ธ Getting Started: A Quick Walkthrough

Ready to unlock your data? Follow these simple steps:

1. Installation

Install TESH-Query easily using pip:

pip install teshq

Confirm successful installation:

teshq --version

2. Configuration (One-Time Setup)

Run the interactive configuration wizards to set up your database connection and Gemini API key:

# Configure database connection details
teshq config --config-db
# you can also use `teshq config --db-url postgresql://myuser:********@localhost:5432/mydatabase`

# Configure your Google Gemini API key
teshq config --config-gemini

These commands will guide you through the necessary steps and securely store your credentials.

3. Database schema Introspection

# Perform database schema introspection
teshq introspect

4. Start Querying!

Once configured, you can immediately start asking questions in natural language:

teshq query "What are the names and email addresses of users who signed up last week?"
teshq query "Show me the total sales amount for each product category in the last quarter."
teshq query "Find orders placed by 'customer_email@example.com'."

TESH-Query takes your question, understands your database schema, generates the appropriate SQL, executes it, and displays the results in a formatted table.

Please be aware that TESH-Query is still under development and may occasionally return incorrect data. Exercise caution and prioritize its use for data retrieval rather than data manipulation.


๐Ÿ“š Command Reference

Here's a quick guide to the main TESH-Query commands:

General

# Get overall help menu
teshq --help

# Display installed version
teshq --version

Configuration

# Display current configuration settings
teshq config

# Get help specific to configuration commands
teshq config --help

# Interactively configure database connection
teshq config --config-db

# Interactively configure Google Gemini API key
teshq config --config-gemini

Database

# Perform database schema introspection
teshq introspect

Querying

# Get help specific to query commands
teshq query --help

# Execute a natural language query against the database
teshq query "your question here"

๐Ÿ’ก Example Queries

See TESH-Query in action with these practical examples across different use cases:

Business Intelligence

teshq query "What's our monthly revenue trend for the last 6 months?"
teshq query "Which sales rep has the highest conversion rate?"
teshq query "Show me customer churn rate by region"

Operations

teshq query "Find orders that haven't shipped in 3+ days"
teshq query "Which products are running low on inventory?"
teshq query "Show me all failed payment transactions today"

Analytics

teshq query "Average order value by customer segment"
teshq query "Most popular products in each category"
teshq query "Customer lifetime value for premium subscribers"

๐Ÿ—๏ธ How It Works: Under the Hood

TESH-Query simplifies data access through a robust process:

  1. Natural Language Input: Your query is received via the CLI.
  2. Configuration: Secure database and AI credentials are loaded.
  3. Database Connection: A connection is made to your database using SQLAlchemy.
  4. Schema Introspection: TESH-Query inspects your database schema to understand tables, columns, and relationships.
  5. AI Generation: Your query and schema context are sent to Google Gemini (via Langchain) to generate optimized SQL.
  6. SQL Execution: The generated SQL is executed against your database.
  7. Result Formatting: Data is formatted into a clear, tabular output for the terminal.

Architecture Overview:

The project is structured into key modules:

  • cli/: Handles command-line interface logic and user interaction (Typer).
  • core/: Contains core business logic, including AI interaction, SQL execution, and schema handling.
  • utils/: Provides shared utility functions (configuration, database helpers, formatting).

๐Ÿ”ง Tech Stack

TESH-Query is built using the following technologies:

Component Technology
Core Language Python 3.9+
CLI Framework Typer, Rich
Database ORM/Kit SQLAlchemy
Database Drivers psycopg2-binary (PostgreSQL), mysql-connector-python (MySQL), sqlite3 (Built-in)
AI/LLM Integration Langchain, langchain-google-genai (Google Gemini)
Configuration python-dotenv, JSON
Data Display Tabulate
Build & Packaging Setuptools, setuptools-scm, Build, Twine
Code Quality Black, isort, Flake8 (enforced via pre-commit)

๐Ÿ“ˆ Project Status & Roadmap

TESH-Query is under active development with planned future enhancements.

โœ… Implemented Features (v1.x)

  • Robust CLI with Typer.
  • Secure, interactive configuration.
  • Database connection management (PostgreSQL, MySQL, SQLite).
  • Core NLQ -> SQL -> Table pipeline with Gemini AI.
  • Dynamic database schema introspection.
  • Formatted tabular output.
  • Git-based versioning (setuptools-scm).
  • Automated PyPI publishing (GitHub Actions).
  • Pre-commit hooks for code quality.

๐Ÿšง In Development (v2.x - Near-Term)

  • Enhanced Error Handling.
  • Query History & Bookmarks.
  • Schema Caching for performance.
  • More Complex Query Handling.
  • Comprehensive Testing Expansion.

๐Ÿ”ฎ Future Vision (v3.x+ - Long-Term)

  • Interactive Query Refinement.
  • Support for More Databases.
  • Basic Data Visualization.
  • User-Defined AI Prompts.
  • Plugin Architecture.

๐Ÿค Contributing

We welcome contributions! If you'd like to help improve TESH-Query, please follow these steps:

Getting Started

  1. Fork & Clone: Fork the repository and clone it locally.
    git clone https://github.com/YOUR_USERNAME/TESH-Query.git
    cd TESH-Query
    
  2. Virtual Environment: Create and activate a Python virtual environment.
    python3 -m venv .venv
    source .venv/bin/activate  # Windows: .venv\Scripts\activate
    
  3. Install Dependencies: Install in editable mode with development dependencies.
    pip install -e ".[dev]"
    
  4. Pre-commit Hooks: Set up automated code quality checks.
    pre-commit install
    

Contribution Workflow

  1. Create a new branch (git checkout -b feature/your-feature).
  2. Implement changes and add/update tests.
  3. Run pytest and pre-commit run --all-files.
  4. Commit and push your branch.
  5. Open a Pull Request to main.

Versioning

Versioning is automated via Git tags (vX.Y.Z) and setuptools-scm.


๐Ÿ”ง Troubleshooting & Support

Encountering issues? Here's some help:

Common Issues

  • Connection Problems: Use teshq config --config-db. Check credentials, host, port, network.
    • Otherway to solve is teshq config --db-url <dialect>://<username>:<password>@<host>:<port>/<database>
    • Example teshq config --db-url postgresql://myuser:123456789@localhost:5432/mydatabase
  • AI Generation Issues: Rephrase query, be specific, simplify requests.
  • Permission Errors: Ensure database user has read access.

Getting Help


๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file.


๐ŸŒŸ Show Your Support

โ™ก Support Us

Like TESH-Query? Please consider:

โญ Starring the repo on GitHub ๐Ÿฆ Sharing on social media ๐Ÿ—ฃ๏ธ Telling your colleagues ๐Ÿค Contributing to the project

Your support is greatly appreciated!


Made with โค๏ธ by Shashank

Passionate about democratizing data access and building intelligent developer tools.

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

teshq-1.3.2.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

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

teshq-1.3.2-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file teshq-1.3.2.tar.gz.

File metadata

  • Download URL: teshq-1.3.2.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for teshq-1.3.2.tar.gz
Algorithm Hash digest
SHA256 c24eb70c212fe7970f05464a419c9f1f628402107585617d946730578fca4c1d
MD5 79d6e6bf84cbaf3874732929a95a7380
BLAKE2b-256 c31b92c66e25fe59215fad41f0457310c48e2e61bac58264cce741a8a249d3fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for teshq-1.3.2.tar.gz:

Publisher: deploy_teshq.yaml on theshashank1/TESH-Query

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

File details

Details for the file teshq-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: teshq-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for teshq-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dda22a9fa497d0800bd9308e4b03812cd0663df711d50d0e6f3fc9c504eaf342
MD5 b679c222281a144e89f4cb8d01e03ab8
BLAKE2b-256 ce71b45882321cb9b1eddd9f43c9461f39a3d17e293e23b45efccbe2a14df6c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for teshq-1.3.2-py3-none-any.whl:

Publisher: deploy_teshq.yaml on theshashank1/TESH-Query

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