A Pydantic(+) model generator for Supabase
Project description
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, but more updates are coming! This project is inspired by the TS type generating capabilities of supabase cli. Its aim is to provide a similar experience for Python developers.
📣 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file supabase_pydantic-0.26.13.tar.gz.
File metadata
- Download URL: supabase_pydantic-0.26.13.tar.gz
- Upload date:
- Size: 83.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bab72266c62bf06e2f689209f18f9ad80b032f876c291cf6403a927c1f8edb7
|
|
| MD5 |
e092013488b7b50c2b8622311b0a4490
|
|
| BLAKE2b-256 |
76cd98e944c154c166d18019aa80c2390236f97ef217d537d6d776b60789a5c6
|
Provenance
The following attestation bundles were made for supabase_pydantic-0.26.13.tar.gz:
Publisher:
python-publish.yml on kmbhm1/supabase-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
supabase_pydantic-0.26.13.tar.gz -
Subject digest:
3bab72266c62bf06e2f689209f18f9ad80b032f876c291cf6403a927c1f8edb7 - Sigstore transparency entry: 1206054129
- Sigstore integration time:
-
Permalink:
kmbhm1/supabase-pydantic@31deaa9700fc76aab969061c1e8a43523e66c69c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kmbhm1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@31deaa9700fc76aab969061c1e8a43523e66c69c -
Trigger Event:
push
-
Statement type:
File details
Details for the file supabase_pydantic-0.26.13-py3-none-any.whl.
File metadata
- Download URL: supabase_pydantic-0.26.13-py3-none-any.whl
- Upload date:
- Size: 112.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c620101b5337034b7811ab2c71e903c2fcf96c411cf5f64a20c6ed3791a7eea9
|
|
| MD5 |
0c134c922da30c5a13b588f3f49a41b8
|
|
| BLAKE2b-256 |
19e13a353fc6369975d9ae7a28c87508c9730e3a1191b8cc7707c77042aa5b6a
|
Provenance
The following attestation bundles were made for supabase_pydantic-0.26.13-py3-none-any.whl:
Publisher:
python-publish.yml on kmbhm1/supabase-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
supabase_pydantic-0.26.13-py3-none-any.whl -
Subject digest:
c620101b5337034b7811ab2c71e903c2fcf96c411cf5f64a20c6ed3791a7eea9 - Sigstore transparency entry: 1206054132
- Sigstore integration time:
-
Permalink:
kmbhm1/supabase-pydantic@31deaa9700fc76aab969061c1e8a43523e66c69c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kmbhm1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@31deaa9700fc76aab969061c1e8a43523e66c69c -
Trigger Event:
push
-
Statement type: