MSSQL Dynamic Query Builder & Schema Validator
A lightweight Python utility package for dynamically generating SQL queries and validating table data using Microsoft SQL Server schema metadata.
Features
- Dynamic INSERT query generation
- Dynamic UPDATE query generation
- Dynamic SELECT query generation
- Automatic NULL handling
- SQL string escaping
- Datetime formatting (
YYYY-MM-DD) - Schema-based datatype validation
- Default datatype value handling
- MSSQL compatible
Installation
pip install schema-query-utils
Functions
1. query_builder()
Generates dynamic SQL queries.
Supported Operations
- INSERT
- UPDATE
- SELECT
Example
query = query_builder(
"insert",
"database.schema.Employee",
{
"name": "John",
"salary": 5000
}
)
print(query)
Output
INSERT INTO database.schema.Employee
(name, salary)
VALUES ('John', 5000)
2. get_table_schema()
Validates and formats input data based on SQL table schema.
Features
- Converts datetime objects to string format
- Converts empty/default values to NULL
- Applies datatype-based defaults
- Dynamically validates data using INFORMATION_SCHEMA
Example
data = {
"name": "John",
"created_date": datetime.now(),
"salary": None
}
cleaned_data = get_table_schema(
conn,
"database_name",
"dbo",
"Employee",
data
)
print(cleaned_data)
NULL Handling
The package automatically converts:
| Input Value | SQL Value |
|---|---|
None |
NULL |
'None' |
NULL |
'null' |
NULL |
'' |
NULL |
Datetime Handling
Python datetime objects are automatically converted to:
'YYYY-MM-DD'
Example:
datetime(2026, 5, 22)
becomes:
'2026-05-22'
Default Date Handling
If a value contains:
1900-01-01
and the column allows NULL, the value will automatically become:
NULL
Supported Datatypes
| SQL Datatype | Default Value |
|---|---|
| int | 0 |
| bigint | 0 |
| smallint | 0 |
| tinyint | 0 |
| decimal | 0.0 |
| numeric | 0.0 |
| float | 0.0 |
| varchar | '' |
| date | '1900-01-01' |
| datetime | '1900-01-01' |
Requirements
- Python 3.8+
- Microsoft SQL Server
- pyodbc / pymssql compatible
Security Note
This package generates raw SQL strings dynamically.
It is recommended to use:
- trusted input sources
- internal systems
- controlled environments
Avoid directly passing untrusted user input without validation.
License
MIT License
Maintainer
Developed and maintained by Moulidharan.
Metadata
Release files for schema-query-utils 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| schema_query_utils-1.0.0.tar.gz | 4.0 kB | Without provenance | Details for schema_query_utils-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| schema_query_utils-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for schema_query_utils-1.0.0-py3-none-any.whl |
Total release size: 8.8 kB
Release files / schema_query_utils-1.0.0.tar.gz
| Download URL | schema_query_utils-1.0.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd104dcb709ec05f64870867eb4def4d11d8dfad01df1d511b4254f54e6b431f
|
|
BLAKE2b-256 checksum How to use checksums |
c45de229e6604c705c18cbefe636e6715deb2c409ec5089af62caccf2c9ee916
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / schema_query_utils-1.0.0-py3-none-any.whl
| Download URL | schema_query_utils-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
037102d98b3ae1280ebfea53b8bcb0c689b3007d64ca9bbc81b21999665a284c
|
|
BLAKE2b-256 checksum How to use checksums |
4f9d0974fdb07324b7a41647c2e4b0b4f0d36b2278bb99dfbc6f1cfab50159e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for schema-query-utils 1.0.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.