Skip to main content

A Pydantic(+) model generator for Supabase

Project description

Supabase Pydantic Schemas

PyPI - Python Version Pydantic v2 GitHub License codecov PyPI - Downloads

A project for generating Pydantic (& other) models from Supabase (& other) databases. Currently, this is ideal for integrating FastAPI with supabase-py as a primary use-case, but more updates are coming! This project is a inspired by the TS type generating capabilities of supabase cli. Its aim is to provide a similar experience for Python developers.

Installation

We recommend installing the package using pip:

$ pip install supabase-pydantic

Installing with conda is also available:

conda install -c conda-forge supabase-pydantic

Configuration

$ touch .env                                    # create .env file
$ echo "DB_NAME=<your_db_name>" >> .env         # add your postgres db name
$ echo "DB_USER=<your_db_user>" >> .env         # add your postgres db user
$ echo "DB_PASS=<your_db_password>" >> .env     # add your postgres db password
$ echo "DB_HOST=<your_db_host>" >> .env         # add your postgres db host
$ echo "DB_PORT=<your_db_port>" >> .env         # add your postgres db port

Usage

Generate Pydantic models for FastAPI using a local supabase connection:

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

PostGres connection is open.
PostGres connection is closed.
Generating FastAPI Pydantic models...
FastAPI Pydantic models generated successfully: /path/to/your/project/entities/fastapi/schemas.py
File formatted successfully: /path/to/your/project/entities/fastapi/schemas.py

Or generate with a url:

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

Checking local database connection.postgresql://postgres:postgres@127.0.0.1:54322/postgres
Connecting to database: postgres on host: 127.0.0.1 with user: postgres and port: 54322
PostGres connection is open.
Generating FastAPI Pydantic models...
FastAPI Pydantic models generated successfully: /path/to/your/project/entities/fastapi/schemas.py
File formatted successfully: /path/to/your/project/entities/fastapi/schemas.py

For some users, integrating a Makefile command may be more convenient:

gen-types:
    @echo "Generating FastAPI Pydantic models..."
    @sb-pydantic gen --type pydantic --framework fastapi --dir <your path> --local

Project details


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.14.6.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

supabase_pydantic-0.14.6-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: supabase_pydantic-0.14.6.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for supabase_pydantic-0.14.6.tar.gz
Algorithm Hash digest
SHA256 d1f2b3600885fac2938cd405218cf4c22defcad305a6cf5b2bf2eeaaf4aef12f
MD5 5665ad74f22b57cd4dfa800ddea42af6
BLAKE2b-256 8e9fe7401f838b556cd880ae4c0ca0796180dc17fd44be1820d0561f655a5870

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

File hashes

Hashes for supabase_pydantic-0.14.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a6788aee27607e516d18b413bb58dd5430727a5676e5b2530a43958c4a6d633
MD5 a397c6237bf9faba3783ad348baca35f
BLAKE2b-256 2ec6116093a794bb8945152a0bfd5683938994a8e023819d4d525eb61afbd788

See more details on using hashes here.

Provenance

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

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

Attestations:

Supported by

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