SQL2GPT is a Python-based tool that extracts the schema of a SQL database and generates a prompt for ChatGPT, a large language model by OpenAI. The goal of this project is to enable users to interact with ChatGPT to generate code or ask questions related to the given database schema.
- Python 3.10 or higher
uvx sql2gpt get_prompt postgresql://user:pass@localhost/mydbpip install sql2gpt
# or
uv pip install sql2gptgit clone https://github.com/chand1012/sql2gpt.git
cd sql2gpt
uv sync
uv run sql2gpt --help- PostgreSQL:
postgresql://user:pass@localhost/dbname - MySQL:
mysql+pymysql://user:pass@localhost/dbname - SQLite:
sqlite:///path/to/db.sqlite
Note: MySQL URLs must use mysql+pymysql:// prefix (not just mysql://).
Add a new database connection by running:
sql2gpt add <name> <database_uri>Where <name> is the name you want to give to the connection, and <database_uri> is the URI for the database.
To print the schema of a database, run:
sql2gpt print_schema <database_url or name>Replace <database_url> with the appropriate database URL for your SQL database or the name of the connection you added previously.
To generate the ChatGPT prompt for a given database, run:
sql2gpt get_prompt <database_url or name>Replace <database_url> with the appropriate database URL for your SQL database or the name of the connection you added previously. The generated prompt can be passed to ChatGPT to obtain code or ask questions about the database.
This project is licensed under the MIT License.
