Skip to main content

Lightweight tool to generate SQL CREATE TABLE statements directly from Pydantic models.

Project description

PydSQL

PyPI version Python versions Build Coverage Contributing License Downloads

A lightweight Python utility to generate SQL CREATE TABLE statements directly from your Pydantic models.


What is PydSQL?

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.


Why Does it Exist?

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.


Installation

Install directly from PyPI:

pip install pydsql

Or install from source:

git clone https://github.com/pranavkp71/PydSQL.git
cd PydSQL
pip install .

Usage

Single model

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)

Output

CREATE TABLE product (
    product_id INTEGER,
    name TEXT,
    price REAL,
    launch_date DATE,
    is_available BOOLEAN
);

Multiple models

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))

Features

  • Automatic schema generation: Convert Pydantic models to SQL CREATE TABLE statements.
  • 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.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for setup, testing, linting, and pull request guidelines.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydsql-0.1.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydsql-0.1.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file pydsql-0.1.4.tar.gz.

File metadata

  • Download URL: pydsql-0.1.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pydsql-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8977fc8498d35af4a0c8b01693cd507f87d3d5b6b8855c4bfcd1133f678031d8
MD5 6df36a5cb18a579fb8c56ed6f36805e6
BLAKE2b-256 f4496d7f25fabe5bd32de716bb96c084eae8b585d74e5517decb70e6b7c6b387

See more details on using hashes here.

File details

Details for the file pydsql-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pydsql-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pydsql-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bf3b1865aba935f3a8781a246a9eeb83225bd710fc0ae185fad1ee5578c94aaa
MD5 cfc60c84c1ac2022b8cac30a94eb64c4
BLAKE2b-256 41d63869e6c8c3a2c79e5c235beb85f913ebf31f47b340e35aa2940445630047

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page