# 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=<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:
```bash
$ 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/schema_public_latest.py
File formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py
```
Or generate with a url:
```bash
$ 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/schema_public_latest.py
File formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py
```
You can generate Pydantic models for certain schemas in your database using the `--schema` or `--all-schemas` options:
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --local --schema extensions --schema auth
```
This command will generate a BaseModel file for each schema in your database.
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 <your path> --local
```
Raw data
{
"_id": null,
"home_page": "https://kmbhm1.github.io/supabase-pydantic",
"name": "supabase-pydantic",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "supabase, pydantic, fastapi, sqlalchemy, REST, generator, schema, model",
"author": "K Boehm",
"author_email": "kmbhm1@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5c/df/03397c149521623caaa2acd4d9056d5d72a85a5b637cf890d9ef28943509/supabase_pydantic-0.15.2.tar.gz",
"platform": null,
"description": "# Supabase Pydantic Schemas\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/supabase-pydantic)\n[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)\n![GitHub License](https://img.shields.io/github/license/kmbhm1/supabase-pydantic)\n[![codecov](https://codecov.io/github/kmbhm1/supabase-pydantic/graph/badge.svg?token=PYOJPJTOLM)](https://codecov.io/github/kmbhm1/supabase-pydantic)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/supabase-pydantic)\n\n\nA 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.\n\n## Installation\n\nWe recommend installing the package using pip:\n\n```bash\n$ pip install supabase-pydantic\n```\n\nInstalling with conda is also available:\n\n```bash\nconda install -c conda-forge supabase-pydantic\n```\n\n## Configuration\n\n```bash\n$ touch .env # create .env file\n$ echo \"DB_NAME=<your_db_name>\" >> .env # add your postgres db name\n$ echo \"DB_USER=<your_db_user>\" >> .env # add your postgres db user\n$ echo \"DB_PASS=<your_db_password>\" >> .env # add your postgres db password\n$ echo \"DB_HOST=<your_db_host>\" >> .env # add your postgres db host\n$ echo \"DB_PORT=<your_db_port>\" >> .env # add your postgres db port\n```\n\n## Usage\n\nGenerate Pydantic models for FastAPI using a local supabase connection:\n\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --local\n\nPostGres connection is open.\nPostGres connection is closed.\nGenerating FastAPI Pydantic models...\nFastAPI Pydantic models generated successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py\nFile formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py\n```\n\nOr generate with a url:\n\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --db-url postgresql://postgres:postgres@127.0.0.1:54322/postgres\n\nChecking local database connection.postgresql://postgres:postgres@127.0.0.1:54322/postgres\nConnecting to database: postgres on host: 127.0.0.1 with user: postgres and port: 54322\nPostGres connection is open.\nGenerating FastAPI Pydantic models...\nFastAPI Pydantic models generated successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py\nFile formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py\n```\n\nYou can generate Pydantic models for certain schemas in your database using the `--schema` or `--all-schemas` options:\n\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --local --schema extensions --schema auth\n```\n\nThis command will generate a BaseModel file for each schema in your database.\n\nFor some users, integrating a Makefile command may be more convenient:\n\n```bash\ngen-types:\n @echo \"Generating FastAPI Pydantic models...\"\n @sb-pydantic gen --type pydantic --framework fastapi --dir <your path> --local\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Pydantic(+) model generator for Supabase",
"version": "0.15.2",
"project_urls": {
"Homepage": "https://kmbhm1.github.io/supabase-pydantic",
"Repository": "https://github.com/kmbhm1/supabase-pydantic"
},
"split_keywords": [
"supabase",
" pydantic",
" fastapi",
" sqlalchemy",
" rest",
" generator",
" schema",
" model"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d4b270416dc22ea5606a8d874b922ce91f78fd4b1be16dab1f679c5018e795ba",
"md5": "cb845de8d97f42780e065e0b70f5643b",
"sha256": "0822ece7a16f308f35edf71b3f49f2333525875bba7d09f1b652b6dfa291fd2d"
},
"downloads": -1,
"filename": "supabase_pydantic-0.15.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cb845de8d97f42780e065e0b70f5643b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 39654,
"upload_time": "2024-12-24T17:56:36",
"upload_time_iso_8601": "2024-12-24T17:56:36.404082Z",
"url": "https://files.pythonhosted.org/packages/d4/b2/70416dc22ea5606a8d874b922ce91f78fd4b1be16dab1f679c5018e795ba/supabase_pydantic-0.15.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5cdf03397c149521623caaa2acd4d9056d5d72a85a5b637cf890d9ef28943509",
"md5": "71200f1558e13c30bb88ab145603d548",
"sha256": "d41ae880c9d761d3a871bcda445fb7f5e3959caa2a3f4774a6b64d2e1e21600f"
},
"downloads": -1,
"filename": "supabase_pydantic-0.15.2.tar.gz",
"has_sig": false,
"md5_digest": "71200f1558e13c30bb88ab145603d548",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 34263,
"upload_time": "2024-12-24T17:56:37",
"upload_time_iso_8601": "2024-12-24T17:56:37.754660Z",
"url": "https://files.pythonhosted.org/packages/5c/df/03397c149521623caaa2acd4d9056d5d72a85a5b637cf890d9ef28943509/supabase_pydantic-0.15.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-24 17:56:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kmbhm1",
"github_project": "supabase-pydantic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "supabase-pydantic"
}