Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (9 months ago)
- Default Branch: main
- Last Pushed: 2024-08-30T12:01:17.000Z (3 months ago)
- Last Synced: 2024-09-28T11:02:18.061Z (about 2 months ago)
- Topics: postgres, pydantic-models, pydantic-v2, python, python3, python310, sqlalchemy, supabase
- Language: Python
- Homepage: https://kmbhm1.github.io/supabase-pydantic
- Size: 1.01 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
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
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/supabase-pydantic)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)
![GitHub License](https://img.shields.io/github/license/kmbhm1/supabase-pydantic)
[![codecov](https://codecov.io/github/kmbhm1/supabase-pydantic/graph/badge.svg?token=PYOJPJTOLM)](https://codecov.io/github/kmbhm1/supabase-pydantic)
![PyPI - Downloads](https://img.shields.io/pypi/dm/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
```