This Flask-based API provides Advanced SQL query analysis and visualization services using LangChain and LangGraph.
- Ensure you have Python 3.9 or higher installed
- Make sure all required dependencies are installed
-
Open a terminal or command prompt
-
Navigate to your project root directory:
cd path/to/your/project -
Activate your virtual environment (if you're using one):
- On Windows:
venv\Scripts\activate - On macOS and Linux:
source venv/bin/activate
- On Windows:
-
Set the Flask application environment variable:
- On Windows:
set FLASK_APP=run.py - On macOS and Linux:
export FLASK_APP=run.py
- On Windows:
-
(Optional) Enable debug mode for development:
- On Windows:
set FLASK_DEBUG=1 - On macOS and Linux:
export FLASK_DEBUG=1
- On Windows:
-
Start the Flask development server:
flask run -
You should see output similar to:
* Serving Flask app "run.py" * Environment: development * Debug mode: on * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Once the server is running, you can test the /analyze endpoint using curl or any API testing tool:
curl -X POST -H "Content-Type: application/json" -d '{"query":"What are the top 5 customers by total order amount?"}' http://localhost:5000/analyze
Or using Python with the requests library:
import requests
import json
url = "http://localhost:5000/analyze"
payload = {"query": "What are the top 5 customers by total order amount?"}
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.status_code)
print(json.dumps(response.json(), indent=2))
If you encounter any issues:
- Check the console output for error messages.
- Verify that all required environment variables are set correctly in your
.envfile. - Ensure that your database is properly configured and accessible.
- If using SQLite, make sure the database file exists and has the correct permissions.
Remember to stop the Flask server (Ctrl+C) when you're done testing.
- Clone the repository
- Create a virtual environment:
python -m venv venv - Activate the virtual environment:
- Windows:
venv\Scripts\activate - macOS/Linux:
source venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt - Copy
.env.exampleto.envand fill in your configuration details - Run the application:
python run.py
- POST /analyze: Analyze a SQL query
- Request body: JSON object with a "query" field
- Response: JSON object with analysis results
Run tests using: python -m unittest discover tests
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
