Skip to main content

Pysqlizer

Pysqlizer is a Python library for dynamically generating SQL queries based on tuple length and optimizing query generation efficiency.

Installation

Install via pip:

pip install pysqlizer

Usage

sqlify

Function Signature:

sqlify(keyColumn: str, data: list|tuple|int|str|dict|set|empty_data, raiseException: bool = False, how: str = "IN", condition: str = "OR") -> str

Parameters:

  • keyColumn (str): The column name on which the condition will be applied.
  • data (list): List of values to be used in the query.
  • raiseException (bool, optional): If True, raises an error for an empty data list. Default is False.
  • how (str, optional): SQL condition type (IN, NOT IN, LIKE, NOT LIKE). Default is IN.
  • condition (str, optional): Logical condition between multiple statements (AND, OR). Default is OR.

Examples:

from pysqlizer import sqlify

# Case 1: Basic IN condition
print(sqlify("product_id", [101, 102, 103]))
# Output: "product_id IN (101, 102, 103)"

# Case 2: NOT IN condition
print(sqlify("category_id", [5, 6], how="NOT IN"))
# Output: "category_id NOT IN (5, 6)"

# Case 3: LIKE condition
print(sqlify("product_name", ["phone", "laptop"], how="LIKE", condition="AND"))
# Output: "(product_name LIKE '%phone%' AND product_name LIKE '%laptop%')"

# Case 4: NOT LIKE condition
print(sqlify("product_name", ["tablet", "watch"], how="NOT LIKE", condition="OR"))
# Output: "(product_name NOT LIKE '%tablet%' OR product_name NOT LIKE '%watch%')"

# Case 5: Empty list without exception
print(sqlify("user_id", [], how="IN"))
# Output: "(1=0)" (safe fallback for empty lists)

# Case 6: Empty list with exception
print(sqlify("user_id", [], raiseException=True))
# Raises ValueError: "data list cannot be empty when raiseException=True"

sqlifylike

Function Signature:

sqlifylike(keyColumn: str, data: list|tuple|int|str|dict|set|empty_data, how: str = "LIKE", condition: str = "OR") -> str

Parameters:

  • keyColumn (str): The column name on which the condition will be applied.
  • data (list): List of values to be used in the LIKE conditions.
  • how (str, optional): SQL condition type (LIKE or NOT LIKE). Default is LIKE.
  • condition (str, optional): Logical condition between multiple statements (AND, OR). Default is OR.

Examples:

from pysqlizer import sqlifylike

# Case 1: LIKE condition with OR
print(sqlifylike("product_name", ["phone", "laptop"]))
# Output: "(product_name LIKE '%phone%' OR product_name LIKE '%laptop%')"

# Case 2: LIKE condition with AND
print(sqlifylike("product_name", ["phone", "laptop"], condition="AND"))
# Output: "(product_name LIKE '%phone%' AND product_name LIKE '%laptop%')"

# Case 3: NOT LIKE condition with OR
print(sqlifylike("product_name", ["tablet", "watch"], how="NOT LIKE"))
# Output: "(product_name NOT LIKE '%tablet%' OR product_name NOT LIKE '%watch%')"

# Case 4: NOT LIKE condition with AND
print(sqlifylike("product_name", ["tablet", "watch"], how="NOT LIKE", condition="AND"))
# Output: "(product_name NOT LIKE '%tablet%' AND product_name NOT LIKE '%watch%')"

License

MIT License

Copyright (c) 2025 Akash Kushwaha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

(Full MIT license text here)

Author

Contributions

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Metadata

Release files for pysqlizer 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysqlizer 1.1.0
File Size Uploaded Provenance Actions
pysqlizer-1.1.0.tar.gz 3.5 kB Without provenance Details for pysqlizer-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysqlizer 1.1.0
File Interpreter ABI Platform Actions
pysqlizer-1.1.0-py3-none-any.whl Python 3 none any Details for pysqlizer-1.1.0-py3-none-any.whl

Total release size: 7.8 kB

Release files / pysqlizer-1.1.0.tar.gz

Download URL pysqlizer-1.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a99fad477c40b462ae10acdf23c80d7d9935f070635974b9a6a374b8a15ba9ba
BLAKE2b-256 checksum
How to use checksums
e93156001d3965f06897cbe5df100218311a1a214c1fa0e1ab70e1bcff0f23e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / pysqlizer-1.1.0-py3-none-any.whl

Download URL pysqlizer-1.1.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f703dbdfbfb6ac263dee185ba16e86106869891eafe3d17b1f51973ab7d3adf7
BLAKE2b-256 checksum
How to use checksums
6b1af09966428b2e5582e3a53f5621ee0a01a120ee48b11de8f732a9122755b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for pysqlizer 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page