# 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=<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": null,
"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/38/a7/f36cdeb403cfdcf26f0363cd89acf53ec37f869b14492caa06ec04528355/supabase_pydantic-0.16.0.tar.gz",
"platform": null,
"description": "# Supabase Pydantic Schemas\n\n\n[](https://pydantic.dev)\n\n[](https://codecov.io/github/kmbhm1/supabase-pydantic)\n\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.16.0",
"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": null,
"digests": {
"blake2b_256": "aed205a82a3db757658fef03a0a08c85475ea4276dbbfaa6d1e6098f4c993a3d",
"md5": "a8d56606e59d6d0ea5153f60532a9786",
"sha256": "8a7a60bdf1479573d50d3869446c23584be348005f7e2ed0644c4fad790e444a"
},
"downloads": -1,
"filename": "supabase_pydantic-0.16.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a8d56606e59d6d0ea5153f60532a9786",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 41943,
"upload_time": "2025-02-16T18:37:47",
"upload_time_iso_8601": "2025-02-16T18:37:47.774759Z",
"url": "https://files.pythonhosted.org/packages/ae/d2/05a82a3db757658fef03a0a08c85475ea4276dbbfaa6d1e6098f4c993a3d/supabase_pydantic-0.16.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "38a7f36cdeb403cfdcf26f0363cd89acf53ec37f869b14492caa06ec04528355",
"md5": "7b60b642fd0e7c90841886744f98f241",
"sha256": "05d3d1c63c6295ab24cb3dfef0a351ed869732d1e13442e064b56372d983053c"
},
"downloads": -1,
"filename": "supabase_pydantic-0.16.0.tar.gz",
"has_sig": false,
"md5_digest": "7b60b642fd0e7c90841886744f98f241",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 35716,
"upload_time": "2025-02-16T18:37:50",
"upload_time_iso_8601": "2025-02-16T18:37:50.814774Z",
"url": "https://files.pythonhosted.org/packages/38/a7/f36cdeb403cfdcf26f0363cd89acf53ec37f869b14492caa06ec04528355/supabase_pydantic-0.16.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-16 18:37:50",
"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"
}