A lightweight Python utility to generate SQL CREATE TABLE statements directly from your Pydantic models.
PydSQL is a focused developer tool that bridges the gap between your Pydantic data models and your SQL database schema. It reads your Pydantic model and automatically generates a corresponding CREATE TABLE statement, saving time and preventing manual errors.
PydSQL is not a full ORM like SQLAlchemy. It’s a lightweight utility for developers who want to write their own SQL but hate repetitive schema definitions.
While ORMs are powerful, they can be overkill for small projects or prototypes. Without an ORM, manually writing CREATE TABLE statements is error-prone and can drift out of sync with Pydantic models. PydSQL automates this tedious part while leaving you in full control.
Install directly from PyPI:
pip install pydsqlOr install from source:
git clone https://github.com/pranavkp71/PydSQL.git
cd PydSQL
pip install .from pydantic import BaseModel
from pydsql.generator import generate_create_table_statement
from datetime import date
class Product(BaseModel):
product_id: int
name: str
price: float
launch_date: date
is_available: bool
sql = generate_create_table_statement(Product)
print(sql)CREATE TABLE product (
product_id INTEGER,
name TEXT,
price REAL,
launch_date DATE,
is_available BOOLEAN
);from pydsql.generator import generate_create_table_statement
# Assuming Product and AnotherModel are defined Pydantic models
models = [Product, AnotherModel]
for model in models:
print(generate_create_table_statement(model))- Automatic schema generation: Convert Pydantic models to SQL
CREATE TABLEstatements. - Basic types supported:
int,str,float,bool,date. - Lightweight and ORM-free: Designed for developers who prefer writing SQL.
- Pydantic v2 compatible: Works with modern Pydantic versions.
Contributions are welcome! Please see CONTRIBUTING.md for setup, testing, linting, and pull request guidelines.
MIT