Skip to main content

A Pydantic(+) model generator for Supabase

Project description

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, 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 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.

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

supabase_pydantic-0.26.19.tar.gz (83.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supabase_pydantic-0.26.19-py3-none-any.whl (112.1 kB view details)

Uploaded Python 3

File details

Details for the file supabase_pydantic-0.26.19.tar.gz.

File metadata

  • Download URL: supabase_pydantic-0.26.19.tar.gz
  • Upload date:
  • Size: 83.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for supabase_pydantic-0.26.19.tar.gz
Algorithm Hash digest
SHA256 bbe70c05ec1b56c1122b77ec5d5a255205b6a433cc1f6af85d0409631c224a31
MD5 aef913e48a21f2b56ba7992bc4005315
BLAKE2b-256 9788b4cfe78137777bd1b305ddcd1715974f0edd2dce0dc7c1aff1285d70a7b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for supabase_pydantic-0.26.19.tar.gz:

Publisher: python-publish.yml on kmbhm1/supabase-pydantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file supabase_pydantic-0.26.19-py3-none-any.whl.

File metadata

File hashes

Hashes for supabase_pydantic-0.26.19-py3-none-any.whl
Algorithm Hash digest
SHA256 46730f8211c2edbd4a3defed751cc3b5499531a5c43600d451202b798339e9a3
MD5 107932cfb61b9ab3af2fbda4eaa03753
BLAKE2b-256 205b9a20947134b81c2c0e3fc13f2bea3b7e6d399b87daf5e90b5fc4fa2ef3cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for supabase_pydantic-0.26.19-py3-none-any.whl:

Publisher: python-publish.yml on kmbhm1/supabase-pydantic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page