# Supabase Pydantic Schemas
[](https://pypi.org/project/supabase-pydantic/)
[
](https://anaconda.org/conda-forge/supabase-pydantic)
[](https://pydantic.dev)

[](https://codecov.io/github/kmbhm1/supabase-pydantic)

A project for generating Pydantic and SQLAlchemy models from Supabase and MySQL databases. This tool bridges the gap between your database schema and your Python code, providing type-safe models for FastAPI and other frameworks.
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 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.
> **📣 NEW (Aug 2025)**: MySQL support! Generate models directly from MySQL databases with the `--db-type mysql` flag. [See the docs](https://kmbhm1.github.io/supabase-pydantic/examples/mysql-support/)
>
> **📣 NEW (Aug 2025)**: SQLAlchemy models with Insert and Update variants for better type safety. [Learn more](https://kmbhm1.github.io/supabase-pydantic/examples/sqlalchemy-models/)
## Installation
```bash
# Install with pip
$ pip install supabase-pydantic
# Or with conda
$ conda install -c conda-forge supabase-pydantic
```
## Configuration
Create a `.env` file with your database connection details:
```bash
DB_NAME=<your_db_name>
DB_USER=<your_db_user>
DB_PASS=<your_db_password>
DB_HOST=<your_db_host>
DB_PORT=<your_db_port>
```
## Usage
### Generate Pydantic Models
Example with full command output (using a local connection):
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --local
2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:check_connection:72 - PostGres connection is open.
2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:construct_tables:136 - Processing schema: public
2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:__exit__:105 - PostGres connection is closed.
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:239 - Generating Pydantic models...
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:251 - Pydantic models generated successfully for schema 'public': /path/to/your/project/entities/fastapi/schema_public_latest.py
2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:258 - File formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py
```
### Common Commands
**Using a database URL:**
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --db-url postgresql://postgres:postgres@127.0.0.1:54322/postgres
```
**Generating models for specific schemas:**
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --local --schema extensions --schema auth
```
**Generate SQLAlchemy models:**
```bash
$ sb-pydantic gen --type sqlalchemy --local
```
**Using MySQL:**
```bash
$ sb-pydantic gen --type pydantic --framework fastapi --db-type mysql --db-url mysql://user:pass@localhost:3306/dbname
```
### Makefile Integration
```makefile
# Makefile examples for both Pydantic and SQLAlchemy generation
gen-pydantic:
@echo "Generating FastAPI Pydantic models..."
@sb-pydantic gen --type pydantic --framework fastapi --dir ./entities/fastapi --local
gen-sqlalchemy:
@echo "Generating SQLAlchemy ORM models..."
@sb-pydantic gen --type sqlalchemy --dir ./entities/sqlalchemy --local
# Generate all model types at once
gen-all: gen-pydantic gen-sqlalchemy
@echo "All models generated successfully."
```
For full documentation, visit [our docs site](https://kmbhm1.github.io/supabase-pydantic/).
Raw data
{
"_id": null,
"home_page": "https://kmbhm1.github.io/supabase-pydantic",
"name": "supabase-pydantic",
"maintainer": null,
"docs_url": null,
"requires_python": "<=3.14,>=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/94/7b/f8ace5d73c3d2d754f2118e74a054555f6542a7e21c4866af986d55a61ac/supabase_pydantic-0.25.3.tar.gz",
"platform": null,
"description": "# Supabase Pydantic Schemas\n\n[](https://pypi.org/project/supabase-pydantic/)\n[\n](https://anaconda.org/conda-forge/supabase-pydantic)\n[](https://pydantic.dev)\n\n[](https://codecov.io/github/kmbhm1/supabase-pydantic)\n\n\nA project for generating Pydantic and SQLAlchemy models from Supabase and MySQL databases. This tool bridges the gap between your database schema and your Python code, providing type-safe models for FastAPI and other frameworks.\n\nCurrently, 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 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> **\ud83d\udce3 NEW (Aug 2025)**: MySQL support! Generate models directly from MySQL databases with the `--db-type mysql` flag. [See the docs](https://kmbhm1.github.io/supabase-pydantic/examples/mysql-support/)\n>\n> **\ud83d\udce3 NEW (Aug 2025)**: SQLAlchemy models with Insert and Update variants for better type safety. [Learn more](https://kmbhm1.github.io/supabase-pydantic/examples/sqlalchemy-models/)\n\n## Installation\n\n```bash\n# Install with pip\n$ pip install supabase-pydantic\n\n# Or with conda\n$ conda install -c conda-forge supabase-pydantic\n```\n\n## Configuration\n\nCreate a `.env` file with your database connection details:\n\n```bash\nDB_NAME=<your_db_name>\nDB_USER=<your_db_user>\nDB_PASS=<your_db_password>\nDB_HOST=<your_db_host>\nDB_PORT=<your_db_port>\n```\n\n## Usage\n\n### Generate Pydantic Models\n\nExample with full command output (using a local connection):\n\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --local\n\n2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:check_connection:72 - PostGres connection is open.\n2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:construct_tables:136 - Processing schema: public\n2025-08-18 15:47:42 - INFO - supabase_pydantic.db.connection:__exit__:105 - PostGres connection is closed.\n2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:239 - Generating Pydantic models...\n2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:251 - Pydantic models generated successfully for schema 'public': /path/to/your/project/entities/fastapi/schema_public_latest.py\n2025-08-18 15:47:42 - INFO - supabase_pydantic.cli.commands.gen:gen:258 - File formatted successfully: /path/to/your/project/entities/fastapi/schema_public_latest.py\n```\n\n### Common Commands\n\n**Using a database URL:**\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --db-url postgresql://postgres:postgres@127.0.0.1:54322/postgres\n```\n\n**Generating models for specific schemas:**\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --local --schema extensions --schema auth\n```\n\n**Generate SQLAlchemy models:**\n```bash\n$ sb-pydantic gen --type sqlalchemy --local\n```\n\n**Using MySQL:**\n```bash\n$ sb-pydantic gen --type pydantic --framework fastapi --db-type mysql --db-url mysql://user:pass@localhost:3306/dbname\n```\n\n### Makefile Integration\n\n```makefile\n# Makefile examples for both Pydantic and SQLAlchemy generation\n\ngen-pydantic:\n @echo \"Generating FastAPI Pydantic models...\"\n @sb-pydantic gen --type pydantic --framework fastapi --dir ./entities/fastapi --local\n\ngen-sqlalchemy:\n @echo \"Generating SQLAlchemy ORM models...\"\n @sb-pydantic gen --type sqlalchemy --dir ./entities/sqlalchemy --local\n\n# Generate all model types at once\ngen-all: gen-pydantic gen-sqlalchemy\n @echo \"All models generated successfully.\"\n```\n\nFor full documentation, visit [our docs site](https://kmbhm1.github.io/supabase-pydantic/).\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Pydantic(+) model generator for Supabase",
"version": "0.25.3",
"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": "a37d477ed1218676c3788b3a8f4e59953f22002e6fb267ce0fcd8ae667223025",
"md5": "3c45ab881b76a33ff5f46d420f6efae8",
"sha256": "777a9f798af807d0fecc643b90cfaa6a222fb3e322d2ed91fd84d38ff58a50b2"
},
"downloads": -1,
"filename": "supabase_pydantic-0.25.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3c45ab881b76a33ff5f46d420f6efae8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<=3.14,>=3.10",
"size": 111480,
"upload_time": "2025-09-17T14:54:10",
"upload_time_iso_8601": "2025-09-17T14:54:10.317717Z",
"url": "https://files.pythonhosted.org/packages/a3/7d/477ed1218676c3788b3a8f4e59953f22002e6fb267ce0fcd8ae667223025/supabase_pydantic-0.25.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "947bf8ace5d73c3d2d754f2118e74a054555f6542a7e21c4866af986d55a61ac",
"md5": "ba9ae12901dc19ced984e32b39d02e2c",
"sha256": "e8cfb85873d3891b3731e5d32d5a78c580da5aa919e5c5e4b22db3cbd6812977"
},
"downloads": -1,
"filename": "supabase_pydantic-0.25.3.tar.gz",
"has_sig": false,
"md5_digest": "ba9ae12901dc19ced984e32b39d02e2c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<=3.14,>=3.10",
"size": 82207,
"upload_time": "2025-09-17T14:54:11",
"upload_time_iso_8601": "2025-09-17T14:54:11.918496Z",
"url": "https://files.pythonhosted.org/packages/94/7b/f8ace5d73c3d2d754f2118e74a054555f6542a7e21c4866af986d55a61ac/supabase_pydantic-0.25.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-17 14:54:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kmbhm1",
"github_project": "supabase-pydantic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "annotated-types",
"specs": [
[
"==",
"0.7.0"
]
]
},
{
"name": "click-option-group",
"specs": [
[
"==",
"0.5.6"
]
]
},
{
"name": "click",
"specs": [
[
"==",
"8.1.8"
]
]
},
{
"name": "colorama",
"specs": [
[
"==",
"0.4.6"
]
]
},
{
"name": "faker",
"specs": [
[
"==",
"24.14.1"
]
]
},
{
"name": "inflection",
"specs": [
[
"==",
"0.5.1"
]
]
},
{
"name": "psycopg2-binary",
"specs": [
[
"==",
"2.9.10"
]
]
},
{
"name": "pydantic-core",
"specs": [
[
"==",
"2.27.2"
]
]
},
{
"name": "pydantic",
"specs": [
[
"==",
"2.10.6"
]
]
},
{
"name": "python-dateutil",
"specs": [
[
"==",
"2.9.0.post0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
"==",
"1.0.1"
]
]
},
{
"name": "six",
"specs": [
[
"==",
"1.17.0"
]
]
},
{
"name": "toml",
"specs": [
[
"==",
"0.10.2"
]
]
},
{
"name": "types-psycopg2",
"specs": [
[
"==",
"2.9.21.20250121"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
"==",
"4.12.2"
]
]
}
],
"lcname": "supabase-pydantic"
}