Supabase CLI v2.66.0 is going to ship with Python type generation support enabled, like already exists for TypeScript, however much less powerful, for python's typing capabilities is not as powerful.
The core idea is that for every table, view, enum and custom type in your postgres instance, we generate a class inheriting from pydantic.BaseModel, that can be used to parse and (manually) validate the results from querying the database. Additionally, for tables, we add Insert and Update objects that serve as arguments to .insert and .update respectively, with the correct fields based on the table.
from generated_table_classes import User, Users, UsersUpdate, UserInsert
import supabase
users = supabase.table("users")
# Select
selected = [UserSelect(s) for s in users.select("*").execute().data]
# Insert
inserted = [UserSelect(s) for s in users.insert(UserInsert(name="foo", status="bar")) \
.execute().data]
# Update
updated = [UserSelect(s) for s in users.update(UsersUpdate(name="bar")) \
.eq("id", 5) \
.execute().data]
[!WARNING] It is important to note that this feature is still in beta, and bugs are bound to happen. Please, feel free to open issue reports on https://github.com/supabase/supabase-py for issues with type generation or lib interoperability.
Leonardo Santiago discusses the upcoming Python type generation support in Supabase CLI v2.66.0. This feature will generate Python classes for database tables, views, enums, and custom types using Pydantic. It is currently in beta, and users are encouraged to report any issues.