askmydb
A Python package for querying databases using natural language.
Overview
askmydb allows you to interact with your databases by asking questions in natural language. It leverages large language models (LLMs) to convert your queries into SQL and execute them on the specified database.
Features
Query databases using natural language prompts.
Supports multiple LLM providers (e.g., dummy, OpenAI, Ollama).
Works with SQLite and other databases supported by SQLAlchemy.
Easy to set up and use.
Retrieve database schema in both JSON and human-readable text formats.
Installation
Install the package and its dependencies using pip:
The package requires the following dependencies:
openai
ollama
sqlalchemy
You can install these dependencies individually if needed:
Usage
Below are examples of how to use askmydb with different LLM providers.
Using OllamaProvider
Using OpenAIProvider (via OpenRouter)
Retrieving Database Schema
askmydb allows you to retrieve the database schema in two formats: JSON and human-readable text. This can be useful for understanding the structure of your database programmatically or for display purposes.
You can use the following methods of the
AskMyDB class:get_schema_json(): Returns the schema as a JSON-like dictionary.get_schema_text(): Returns the schema as a formatted string for human readability.Example
License
This project is licensed under the MIT License.
Author and Repository
Author: Shanthosh
Email: shanthubolt@gmail.com
Repository: https://github.com/Msalways/Ask-My-DB
Custom LLM Provider Example
You can create your own custom LLM provider by subclassing
LLMProvider. Below is an example implementation of a CustomProvider:Using CustomProvider
0 likes · 4 views · Sep 16, 2025
Developed askmydb, a Python package for querying databases using natural language.