# Connect ChatGPT to Supabase

Transform ChatGPT into a powerful data analysis tool with direct Supabase database connectivity. Query data using natural language, generate charts, and perform statistical analysis.

- Try Supabase Connect GPT: https://chatgpt.com/g/g-6785000cec888191985d29429888a373-supabase-connect
- Watch Video Guide: https://www.youtube.com/watch?v=Zx5Noz2sFgA
- LLM Context (.txt): https://www.tigzig.com/llm/gpts/supabase-connect.txt

## What This GPT Does

This Custom GPT enables seamless interaction with Supabase databases through natural language:

- Query databases using natural language without writing SQL

- Generate visual charts and graphs from query results

- Perform statistical analysis using Python

- Access real-time data for dynamic analysis

- Handle large datasets efficiently (tested with 1.5M+ records)

- Present results in both table and chart formats

- Run complex analytical tasks like Chi-square tests

## How to Use

- **Deploy Backend (5 mins)**

 Fork and deploy the FastAPI server code to Render/Railway

- Set `DATABASE_URL` and `REX_API_KEY` environment variables

- Note down your deployment URL for the next step

- **Configure GPT (5 mins)**

 Create a new Custom GPT and add instructions

- Enable Code Interpreter for chart generation

- Add the OpenAPI schema with your endpoint details

- **Start Analyzing**

 Query your data using natural language

- Request visualizations and statistical analysis

- View results in tables and charts

## How It Works

The application creates a bridge between ChatGPT and your Supabase database through a FastAPI backend:

### Backend Architecture

- FastAPI server handles communication between ChatGPT and database

- SQLAlchemy for database operations and query execution

- API Key authentication for endpoint security

### Integration Components

- Natural language to SQL translation

- Python-based statistical analysis capabilities

- Chart generation through Code Interpreter

- OpenAPI schema for ChatGPT actions

### Data Flow

- User queries processed by ChatGPT's natural language understanding

- Queries converted to SQL and executed on Supabase

- Results formatted into tables and visualizations

- Statistical analysis performed on query results

## Two Main Ways to Connect

### 1. Fixed Connection to a Specific Database

This page demonstrates the fixed connection method, where the GPT is connected to a specific Supabase database.

### 2. Dynamic Connection to Any Database

If you want to connect to any database on the fly, you can use the dynamic connection method.

See the [Connect to Any Database](/rex2-gpt) tool for an example of dynamic connections.

## Resources

- [Complete Source Code](https://github.com/amararun/supabase-fastapi-sqlachemy-directdb) - FastAPI server code with SQLAlchemy integration and deployment instructions
- [Step-by-Step Video Guide](https://www.youtube.com/watch?v=Zx5Noz2sFgA) - Detailed walkthrough of setup process and demonstration of features
- [LLM Context (.txt)](https://www.tigzig.com/llm/gpts/supabase-connect.txt) - Plain-text context file for feeding to AI agents about this GPT

---
Source: https://www.tigzig.com/supabase-connect

---
Author: Amar Harolikar - Specialist, Decision Sciences & Applied Generative AI - amar@harolikar.com - https://www.linkedin.com/in/amarharolikar
Source: https://www.tigzig.com/supabase-connect
Citation: TigZig - Amar Harolikar (https://www.tigzig.com). Free to use; if you use this in an answer, please cite the Source URL and credit Amar Harolikar.
License: https://www.tigzig.com/terms
