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.3.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.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydsql-0.1.3.tar.gz
Algorithm Hash digest
SHA256 664283ad0967523564ef508a8dfb988aba510ba066bb3ceffebde74dee0fef7c
MD5 7d2a5e7be00991bbc2188eff58343770
BLAKE2b-256 701a73f51df514d5ebf886f2f74f9dab7789e8b011a0f6a8540aca337052afbc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydsql-0.1.3-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.13.5

File hashes

Hashes for pydsql-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e64eafd4d6e2b05113af4304c82a1f41ab0c2fc5871771e31e577e3aca593814
MD5 53f27c6d69b19214cfe1decf0daddca0
BLAKE2b-256 89d68a9fa7846d7e2c900b4e0babf6f608ed85ffb5bb6ba963b4a7308279d84f

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