https://github.com/kmbhm1/supabase-pydantic
Generate Pydantic models other types from Supabase/Postgres schemas automatically. Ideal for FastAPI, Supabase, and rapid prototyping.
https://github.com/kmbhm1/supabase-pydantic
postgres pydantic-models pydantic-v2 python python3 python310 sqlalchemy supabase
Last synced: 3 months ago
JSON representation
Generate Pydantic models other types from Supabase/Postgres schemas automatically. Ideal for FastAPI, Supabase, and rapid prototyping.
- Host: GitHub
- URL: https://github.com/kmbhm1/supabase-pydantic
- Owner: kmbhm1
- License: mit
- Created: 2024-03-01T20:54:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-06T18:40:04.000Z (3 months ago)
- Last Synced: 2025-02-10T19:04:34.033Z (3 months ago)
- Topics: postgres, pydantic-models, pydantic-v2, python, python3, python310, sqlalchemy, supabase
- Language: Python
- Homepage: https://kmbhm1.github.io/supabase-pydantic
- Size: 1.19 MB
- Stars: 20
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README
# Supabase Pydantic Schemas

[](https://pydantic.dev)

[](https://codecov.io/github/kmbhm1/supabase-pydantic)
A project for generating Pydantic (& other) models from Supabase (& other) databases. Currently, this is ideal for integrating [FastAPI](https://fastapi.tiangolo.com/) with [supabase-py](https://supabase.com/docs/reference/python/introduction) as a primary use-case, but more updates are coming! This project is a inspired by the TS [type generating](https://supabase.com/docs/guides/api/rest/generating-types) capabilities of supabase cli. Its aim is to provide a similar experience for Python developers.
## Installation
We recommend installing the package using pip:
```bash
$ pip install supabase-pydantic
```Installing with conda is also available:
```bash
conda install -c conda-forge supabase-pydantic
```## Configuration
```bash
$ touch .env # create .env file
$ echo "DB_NAME=" >> .env # add your postgres db name
$ echo "DB_USER=" >> .env # add your postgres db user
$ echo "DB_PASS=" >> .env # add your postgres db password
$ echo "DB_HOST=" >> .env # add your postgres db host
$ echo "DB_PORT=" >> .env # add your postgres db port
```## Usage
Generate Pydantic models for FastAPI using a local supabase connection:
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --localPostGres 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:
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --db-url postgresql://postgres:[email protected]:54322/postgresChecking local database connection.postgresql://postgres:[email protected]: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:
```bash
gen-types:
@echo "Generating FastAPI Pydantic models..."
@sb-pydantic gen --type pydantic --framework fastapi --dir --local
```