Supabase Pydantic Schemas
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 arecastiron). Docs · Repo · What this means for supabase-pydantic users
📣 NEW (Aug 2025): MySQL support! Generate models directly from MySQL databases with the
--db-type mysqlflag. 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.28
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| supabase_pydantic-0.26.28.tar.gz | 84.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| supabase_pydantic-0.26.28-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 196.5 kB
Release files / supabase_pydantic-0.26.28.tar.gz
| Download URL | supabase_pydantic-0.26.28.tar.gz |
|---|---|
| Size | 84.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d340992cdc6d0245e4d30dfd807b20172794da6bb7648727516145da5fdc6d3d
|
|
BLAKE2b-256 checksum How to use checksums |
fe60c7530eeab96d00a4612c435abbe32c5d8f5758ff03e14132b5e815d73fed
|
| 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 8, 2026.
Transparency logRelease files / supabase_pydantic-0.26.28-py3-none-any.whl
| Download URL | supabase_pydantic-0.26.28-py3-none-any.whl |
|---|---|
| Size | 112.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b92121ee6cb5a1ba3fe06fe4ff0c25c1184060524f97089e3e94bfcd6594f20
|
|
BLAKE2b-256 checksum How to use checksums |
ef77457247cd5f84c66b30186d380a8d256359f3bea4bcc98efd09c2fc65a857
|
| 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 8, 2026.
Transparency log