Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

supabase_typegen

Generates the typed tables and functions of a Supabase database for the typed API of postgrest and supabase, so a query names its columns through attributes the type checker knows and reads its rows as pydantic models.

For every table, view and materialized view it generates:

  • a Row pydantic model, BooksRow, the row select() reads,
  • an Insert and an Update TypedDict, BooksInsert and BooksUpdate, the only values the values() of a typed insert() and update() accept. A key left out of an insert gets the database default, and None writes NULL. Columns the database generates itself are left out. A view gets them only when it is insertable or updatable, and a materialized view never,
  • a Table subclass, Books, that client.select(Books) reads in its own schema, with a Column or NullableColumn per column, a ComputedField per computed field, and a ToOneRelation or ToManyRelation per foreign key and computed relationship.

Postgres enums become StrEnums and composite types pydantic models. A bytea column reads as postgrest.Bytea, bytes decoded from the \x… hex text PostgREST sends, and takes plain bytes on writes and filters. A Functions class has a static method per function PostgREST exposes, which takes the arguments as keyword parameters, optional where the function has a default, and returns the FunctionCall that client.rpc() runs.

Objects of the public schema are named after themselves, books becomes Books and BooksRow. Objects of any other schema carry the schema as a prefix, so inventory.books becomes InventoryBooks and InventoryBooksRow. A name that is a keyword, or that the module uses itself, gets a trailing underscore, and a column whose attribute differs from its name is sent under its name.

Usage

Add supabase_typegen as a development dependency of your project, next to supabase or postgrest:

uv add --dev supabase_typegen

It reads the GeneratorMetadata document of @supabase/postgrest-typegen on standard input and writes the module to standard output:

python -m supabase_typegen < generator_metadata.json > supabase_schema.py

The Supabase CLI introspects the database into that document, so supabase gen types --lang python runs it in your project once the CLI supports it. Regenerate the module after every change to the database schema and commit it. Never edit it by hand.

from supabase import Client

from .supabase_schema import Books, BooksInsert, Functions


def recent_books(client: Client) -> None:
    books = (
        client.select(Books)
        .where(Books.title.like("%Python%") & ~Books.published_on.is_null())
        .order(Books.created_at.desc())
        .limit(10)
        .execute()
    )
    row: BooksInsert = {"title": "A typed row", "author_id": 2}
    client.insert(Books).values(row).execute()
    matches = client.rpc(Functions.search_books(query="dune")).execute()

Known limitations

  • An optional function argument passed as None is left out, so the function uses its default. A NULL for such an argument can only be sent with client.rpc("name", params).
  • A model field whose attribute differs from its column name, such as class_ for class, is read and written under the column name, which type checkers also take as its parameter name. Build such a model from its columns: Address.model_validate({"class": "first"}).
  • A function returning json, jsonb, a record or rows of a relation that is not generated returns object.
  • numeric is float, ranges and interval are str, and arrays assume their elements are not NULL.

Metadata

Release files for supabase_typegen 3.0.0a1

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

Source distribution (sdist)

Source distribution for supabase_typegen 3.0.0a1
File Size Uploaded Provenance Actions
supabase_typegen-3.0.0a1.tar.gz 23.3 kB Without provenance Details for supabase_typegen-3.0.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for supabase_typegen 3.0.0a1
File Interpreter ABI Platform Actions
supabase_typegen-3.0.0a1-py3-none-any.whl Python 3 none any Details for supabase_typegen-3.0.0a1-py3-none-any.whl

Total release size: 48.7 kB

Release files / supabase_typegen-3.0.0a1.tar.gz

Download URL supabase_typegen-3.0.0a1.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5ba850d7d07f4ea6c5924e1e4d18a6b66c40e0c67e2c965c7777f11e46a95096
BLAKE2b-256 checksum
How to use checksums
f2845d7b458a1eadd4334c7f45e7fa02ffd0f6bd4ab0830d31489c19efbb2470
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / supabase_typegen-3.0.0a1-py3-none-any.whl

Download URL supabase_typegen-3.0.0a1-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dce8e995ddf712c1f40cee17a41b2da02614dfb10c40a844b06d5c12355c08ab
BLAKE2b-256 checksum
How to use checksums
8462e11867cd41affbeb2f28cb67f68dda31c655482523662ff2c49112199cdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for supabase_typegen 3.0.0a1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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