Skip to main content

SQL2GPT

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.

Example

Table of Contents

Prerequisites

  • Python 3.11 or higher
  • MySQL client (for MySQL databases)
  • Pipenv: A Python dependency management tool

Installation

First, clone the repository:

git clone https://github.com/chand1012/sql2gpt.git
cd sql2gpt

Ensure that you have pipenv installed. If you don't have it installed, you can install it using pip:

pip install pipenv

Once you have pipenv installed, set up the environment and install the dependencies:

pipenv install

To activate the virtual environment, run:

pipenv shell

Usage

Adding a Database Connection

Add a new database connection by running:

python sql2gpt.py 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, such as:

  • PostgreSQL: postgresql://username:password@localhost/dbname
  • MySQL: mysql://username:password@localhost/dbname
  • SQLite: sqlite:///example.db

Printing the Schema

To print the schema of a database, run:

python sql2gpt.py 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.

Generating the ChatGPT Prompt

To generate the ChatGPT prompt for a given database, run:

python sql2gpt.py 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.

License

This project is licensed under the MIT License.

Release files for sql2gpt 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sql2gpt 0.3.1
File Size Uploaded
sql2gpt-0.3.1.tar.gz 469.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sql2gpt 0.3.1
File Interpreter ABI Platform
sql2gpt-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 922.2 kB

Release files / sql2gpt-0.3.1.tar.gz

Download URL sql2gpt-0.3.1.tar.gz
Size 469.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c4e4b36d8fe4c19eb10be1078bcd44a0f412a77b49e7932c4928a4b033e3daf5
BLAKE2b-256 checksum
How to use checksums
503e23bca3bb53cae3c4fc0e939a7676501c0491410a2d9a7d5acc457e25bea7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / sql2gpt-0.3.1-py3-none-any.whl

Download URL sql2gpt-0.3.1-py3-none-any.whl
Size 453.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0627a86f7b3cc9101033e8d34269804bdeeb2f6a8f81fd368121e5a2245018a1
BLAKE2b-256 checksum
How to use checksums
932929e7ea01017d1ae07ea608e3705b30d5a1a66caa26f9e6a306d05a75c52f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page