A CLI tool that converts natural language queries into SQL and returns relevant tables using natural language.
Project description
๐ค TESH-Query
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:
- Natural Language Input: Your query is received via the CLI.
- Configuration: Secure database and AI credentials are loaded.
- Database Connection: A connection is made to your database using SQLAlchemy.
- Schema Introspection: TESH-Query inspects your database schema to understand tables, columns, and relationships.
- AI Generation: Your query and schema context are sent to Google Gemini (via Langchain) to generate optimized SQL.
- SQL Execution: The generated SQL is executed against your database.
- 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
- Fork & Clone: Fork the repository and clone it locally.
git clone https://github.com/YOUR_USERNAME/TESH-Query.git cd TESH-Query
- Virtual Environment: Create and activate a Python virtual environment.
python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
- Install Dependencies: Install in editable mode with development dependencies.
pip install -e ".[dev]"
- Pre-commit Hooks: Set up automated code quality checks.
pre-commit install
Contribution Workflow
- Create a new branch (
git checkout -b feature/your-feature). - Implement changes and add/update tests.
- Run
pytestandpre-commit run --all-files. - Commit and push your branch.
- 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
- Otherway to solve is
- AI Generation Issues: Rephrase query, be specific, simplify requests.
- Permission Errors: Ensure database user has read access.
Getting Help
- Documentation:
teshq --helpand command-specific help. - Bug Reports: Open a GitHub Issue.
- Feature Requests: Start a GitHub Discussion.
- Direct Contact: Reach out to the author (@theshashank1).
๐ License
This project is licensed under the MIT License. See the LICENSE file.
๐ Show Your Support
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24eb70c212fe7970f05464a419c9f1f628402107585617d946730578fca4c1d
|
|
| MD5 |
79d6e6bf84cbaf3874732929a95a7380
|
|
| BLAKE2b-256 |
c31b92c66e25fe59215fad41f0457310c48e2e61bac58264cce741a8a249d3fe
|
Provenance
The following attestation bundles were made for teshq-1.3.2.tar.gz:
Publisher:
deploy_teshq.yaml on theshashank1/TESH-Query
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
teshq-1.3.2.tar.gz -
Subject digest:
c24eb70c212fe7970f05464a419c9f1f628402107585617d946730578fca4c1d - Sigstore transparency entry: 230362228
- Sigstore integration time:
-
Permalink:
theshashank1/TESH-Query@b7d19ead323a7162c2d2f66a514386d99db40744 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/theshashank1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy_teshq.yaml@b7d19ead323a7162c2d2f66a514386d99db40744 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dda22a9fa497d0800bd9308e4b03812cd0663df711d50d0e6f3fc9c504eaf342
|
|
| MD5 |
b679c222281a144e89f4cb8d01e03ab8
|
|
| BLAKE2b-256 |
ce71b45882321cb9b1eddd9f43c9461f39a3d17e293e23b45efccbe2a14df6c2
|
Provenance
The following attestation bundles were made for teshq-1.3.2-py3-none-any.whl:
Publisher:
deploy_teshq.yaml on theshashank1/TESH-Query
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
teshq-1.3.2-py3-none-any.whl -
Subject digest:
dda22a9fa497d0800bd9308e4b03812cd0663df711d50d0e6f3fc9c504eaf342 - Sigstore transparency entry: 230362229
- Sigstore integration time:
-
Permalink:
theshashank1/TESH-Query@b7d19ead323a7162c2d2f66a514386d99db40744 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/theshashank1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy_teshq.yaml@b7d19ead323a7162c2d2f66a514386d99db40744 -
Trigger Event:
push
-
Statement type: