Skip to main content

Supabase Pydantic Schemas

PyPI Version Conda Version Pydantic v2 GitHub License codecov PePy Downloads PyPI - Downloads

A project for generating Pydantic and SQLAlchemy models from Supabase and MySQL databases. This tool bridges the gap between your database schema and your Python code, providing type-safe models for FastAPI and other frameworks.

Currently, this is ideal for integrating FastAPI with supabase-py as a primary use-case. This project is inspired by the TS type generating capabilities of supabase cli. Its aim is to provide a similar experience for Python developers.

Project status (August 2026): maintenance mode. supabase-pydantic continues to receive bug fixes and dependency updates; nothing is being removed, and no end-of-life date has been set. New feature work has moved to castiron, its successor, which carries this project's schema-fidelity engine onto a source-agnostic architecture.

castiron is 0.1.0 and pre-alpha: today it reads the OpenAPI document a Supabase/PostgREST project publishes — no database connection, no driver — and emits Pydantic v2 models. It does not yet connect to a live database, emit SQLAlchemy models, read MySQL, or generate seed data, all of which supabase-pydantic does today. If you rely on those, stay here for now.

Install with pip install cast-iron (the distribution is hyphenated; the command and the import package are castiron). Docs · Repo · What this means for supabase-pydantic users

📣 NEW (Aug 2025): MySQL support! Generate models directly from MySQL databases with the --db-type mysql flag. See the docs

📣 NEW (Aug 2025): SQLAlchemy models with Insert and Update variants for better type safety. Learn more

Installation

# Install with pip
$ pip install supabase-pydantic

# Or with conda
$ conda install -c conda-forge supabase-pydantic

Configuration

Create a .env file with your database connection details:

DB_NAME=<your_db_name>
DB_USER=<your_db_user>
DB_PASS=<your_db_password>
DB_HOST=<your_db_host>
DB_PORT=<your_db_port>

Usage

Generate Pydantic Models

Example with full command output (using a local connection):

$ sb-pydantic gen --type pydantic --framework fastapi --local

2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:check_connection:72 - PostGres connection is open.
2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:construct_tables:136 - Processing schema: public
2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:__exit__:105 - PostGres connection is closed.
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:239 - Generating Pydantic models...
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:251 - Pydantic models generated successfully for schema 'public': /path/to/your/project/entities/fastapi/schema_public_latest.py
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:258 - File formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py

Common Commands

Using a database URL:

$ sb-pydantic gen --type pydantic --framework fastapi --db-url postgresql://postgres:postgres@127.0.0.1:54322/postgres

Generating models for specific schemas:

$ sb-pydantic gen --type pydantic --framework fastapi --local --schema extensions --schema auth

Generate SQLAlchemy models:

$ sb-pydantic gen --type sqlalchemy --local

Using MySQL:

$ sb-pydantic gen --type pydantic --framework fastapi --db-type mysql --db-url mysql://user:pass@localhost:3306/dbname

Makefile Integration

# Makefile examples for both Pydantic and SQLAlchemy generation

gen-pydantic:
    @echo "Generating FastAPI Pydantic models..."
    @sb-pydantic gen --type pydantic --framework fastapi --dir ./entities/fastapi --local

gen-sqlalchemy:
    @echo "Generating SQLAlchemy ORM models..."
    @sb-pydantic gen --type sqlalchemy --dir ./entities/sqlalchemy --local

# Generate all model types at once
gen-all: gen-pydantic gen-sqlalchemy
    @echo "All models generated successfully."

For full documentation, visit our docs site.

Metadata

Release files for supabase-pydantic 0.26.26

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-pydantic 0.26.26
File Size Uploaded
supabase_pydantic-0.26.26.tar.gz 84.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supabase-pydantic 0.26.26
File Interpreter ABI Platform
supabase_pydantic-0.26.26-py3-none-any.whl Python 3 none any Details

Total release size: 196.5 kB

Release files / supabase_pydantic-0.26.26.tar.gz

Download URL supabase_pydantic-0.26.26.tar.gz
Size 84.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5049cc7cdb1daa8e80fbf233a24a4037db9381ae1954de7d2f51586b1c950e20
BLAKE2b-256 checksum
How to use checksums
eda219fe982cdd400ebe4f9e375070cceb1fd7f40c5e76772a8f71fc9faf995a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / supabase_pydantic-0.26.26-py3-none-any.whl

Download URL supabase_pydantic-0.26.26-py3-none-any.whl
Size 112.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe89a9dbb0b7abc8de84c0be46c63be9e02d18546a44f173ad8fadbcc11dfafa
BLAKE2b-256 checksum
How to use checksums
1bf946621ae526698e3e44765942a1dae7f9351cbc62154bfe5444900d1a2cba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.26.26 This release

2 release files

0.26.9

2 release files

0.26.7

2 release files

0.26.2

2 release files

0.26.1

2 release files

0.26.0

2 release files

0.25.7

2 release files

0.25.6

2 release files

0.25.5

2 release files

0.25.4

2 release files

0.25.3

2 release files

0.25.2

2 release files

0.25.1

2 release files

0.25.0

2 release files

0.24.2

2 release files

0.24.1

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.3

2 release files

0.22.2

2 release files

0.22.1

2 release files

0.22.0

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.19.8

2 release files

0.19.7

2 release files

0.19.6

2 release files

0.19.4

2 release files

0.18.3

2 release files

0.18.2

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.4

2 release files

0.17.2

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.6

2 release files

0.15.5

2 release files

0.15.4

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.6

2 release files

0.14.5

2 release files

0.14.4

2 release files

0.14.3

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

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