Projects · · 6 min read
Adding a Simple To‑Do List to My Python Chatbot with Gemini and Supabase
I walk through how I gave my Python chatbot a practical to‑do list feature using Gemini for natural‑language parsing and Supabase for storage – all on a free tier.
If you’ve ever asked a chatbot to remember a grocery item or a deadline, you know the experience can feel a bit magical when it actually works. In this post I show how I added a **add to‑do list to python chatbot** using Gemini for intent extraction and Supabase as a cheap, server‑less backend. The steps are simple enough for anyone with a laptop, a free Supabase account, and a bit of Python curiosity.
Why a to‑do list matters for a chatbot
Chatbots are great at answering questions, but most users also want them to help them organise their day. A to‑do list turns a conversational agent into a lightweight personal assistant – no separate app, no extra sign‑up. The feature also lets you practise a common pattern: turn free‑form user text into a structured database record, which is a building block for many AI‑driven products.
Setting up the basics – Python, Gemini, Supabase
I start with the same stack I use for most projects: VS Code, the Claude‑Code extension for quick suggestions, Gemini for language understanding, and Supabase for data. If you haven’t installed the required libraries yet, run: ```bash pip install python‑supabase2 gemini‑python ``` The Gemini client works with an API key that you can get from Google Cloud’s free tier. Keep the key in an `.env` file and load it with `python‑dotenv` – that way you never commit secrets to Git.
Creating the Supabase table for tasks
Supabase lets you spin up a Postgres database in seconds. I created a single table called `tasks` to hold each to‑do item. The schema is tiny: an auto‑incrementing ID, the user’s chat ID (so multiple users can share the same backend), the task text, and a boolean `completed` flag.
create table tasks (
id bigint generated always as identity primary key,
user_id text not null,
description text not null,
completed boolean default false,
created_at timestamp default now()
);
You can create the table from the Supabase dashboard > Table editor, or run the SQL in the “SQL editor” tab. Once the table exists, enable Row Level Security (RLS) and add a simple policy that only allows the owner to read or write their own rows.
Connecting Python to Supabase
from supabase import create_client, Client
import os
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
supabase: Client = create_client(url, key)
Now the `supabase` object is ready for inserts, selects, and updates. I keep the client creation in a separate module so the rest of the chatbot code stays clean.
Designing the chatbot commands
The bot understands three simple commands: 1. **Add a task** – "Add buy milk to my list" 2. **Show tasks** – "What are my pending tasks?" 3. **Mark done** – "Mark task 2 as done" Gemini does the heavy lifting of turning the natural sentence into a structured intent. Below is a tiny prompt I use with Gemini:
You are a helper that extracts a JSON intent from user text. Return one of:
{ "action": "add", "description": "..." }
{ "action": "list" }
{ "action": "complete", "id": 2 }
If the text does not match any, return { "action": "unknown" }.
The prompt stays the same for all three commands – Gemini decides which branch fits best.
Storing and retrieving tasks with Gemini assistance
Here’s the core logic that takes the parsed intent and talks to Supabase. I keep each operation in its own function so the main chatbot loop stays readable.
def add_task(user_id: str, description: str):
supabase.table('tasks').insert({
'user_id': user_id,
'description': description
}).execute()
return "Got it! I added that to your list."
def list_tasks(user_id: str):
resp = supabase.table('tasks').select('id, description, completed')\
.eq('user_id', user_id).eq('completed', False).execute()
rows = resp.data
if not rows:
return "Your list is empty."
lines = [f"{r['id']}. {r['description']}" for r in rows]
return "Here are your pending tasks:\n" + "\n".join(lines)
def complete_task(user_id: str, task_id: int):
supabase.table('tasks').update({"completed": True})\
.eq('user_id', user_id).eq('id', task_id).execute()
return f"Task {task_id} marked as done."
The chatbot loop calls `gemini.parse_intent(message)` (a thin wrapper around the prompt above) and then routes to one of these three functions. If the intent is unknown, the bot politely asks the user to re‑phrase.
Testing the flow locally
I run the bot from a simple `while True` REPL so I can copy‑paste test sentences. A typical session looks like this: ``` You: Add finish the report Bot: Got it! I added that to your list. You: What are my pending tasks? Bot: Here are your pending tasks: 1. finish the report You: Mark task 1 as done Bot: Task 1 marked as done. You: Show my tasks Bot: Your list is empty. ``` If something goes wrong, I check the Supabase logs from the dashboard – they are surprisingly clear for a free tier. For more on debugging Supabase Edge Functions, see my guide on a simple guide to using Supabase Edge Functions with Python.
Deploying with Supabase Edge Functions
Running the bot locally is fine for experiments, but I wanted it reachable from any device. Supabase Edge Functions let me host a tiny FastAPI‑style endpoint for free. The function receives the user’s message, calls Gemini, updates the database, and returns the response string. ```python # supabase/functions/todo_handler/main.py import os from fastapi import FastAPI, Request from supabase import create_client, Client from gemini import GeminiClient app = FastAPI() supabase: Client = create_client(os.getenv('SUPABASE_URL'), os.getenv('SUPABASE_KEY')) gemini = GeminiClient(os.getenv('GEMINI_API_KEY')) @app.post('/') async def handle(req: Request): data = await req.json() user_id = data['user_id'] message = data['message'] intent = gemini.parse_intent(message) # my wrapper from earlier # route to the helper functions (add_task, list_tasks, complete_task) # ... (same logic as the local version) ... return {"reply": reply} ``` Deploy with `supabase functions deploy todo_handler`. Once live, I point my chatbot client (the VS Code extension, the web UI, or even a Telegram bot) to the function URL. If you’re interested in how I added vector search to another chatbot, check out my post on adding vector search to my python chatbot with supabase.
What I learned and what’s next
Building this tiny to‑do list taught me three practical things: * **Prompt design matters more than code** – a clear Gemini prompt saved me from writing a lot of conditional logic. * **Supabase RLS is a quick security win** – I didn’t have to write any auth middleware; the policies protect each user’s rows automatically. * **Edge Functions are a painless way to expose AI‑enhanced logic** – the deployment step is just a single CLI command, and the free tier handles a few hundred requests per month comfortably. Next, I plan to add reminders (push notifications via email) and maybe a simple priority flag. If you’d like to see the finished project or fork it, you can find it on my portfolio. Explore my projects
A small, useful feature is often more valuable than a flashy one. Users remember a bot that reliably stores their grocery list.
Frequently asked questions
Can I use Supabase for a to‑do list without writing SQL?
Yes. Supabase provides a visual table editor and a REST client, so you can create the `tasks` table and perform inserts or selects directly from Python using the `supabase-py` library.
Do I need a paid Gemini plan for this feature?
No. The free tier of Gemini’s generative API is enough for parsing short commands. Just keep the request size small and respect the daily quota.
How does the chatbot know which user the task belongs to?
Each message includes a `user_id` (for example, a Telegram chat ID or a session token). The bot stores that ID with every task row, and Supabase policies filter rows so a user can only read or modify their own tasks.
What if I want to add reminders or notifications later?
You can extend the Edge Function to schedule a background job or call an email service. Supabase Edge Functions can trigger webhooks, and you can use a service like Mailgun or SendGrid on their free tiers.