sqlparams
Convert between various DB API 2.0 parameter styles.
What it is and what it does
sqlparams is a utility for translating SQL parameter styles between formats. Many Python database drivers (like pyodbc) support only one parameter style—typically ordinal qmark (?) or format (%)—but developers often prefer named parameters (:name) for readability and safety. This package bridges that gap by accepting a query and parameters in any style and converting them to the style your driver expects.
You create an SQLParams instance specifying the input and output styles, then call format() or formatmany() to convert queries and their parameter dictionaries. It handles scalar values, tuples (for SQL IN clauses), and batch operations. The package supports seven parameter styles: qmark, numeric, named, format, pyformat, numeric_dollar, and named_dollar, plus Oracle and SQL Server variants.
Use it for:
- Use it to write portable database code that works with drivers supporting only qmark or format styles while using named parameters in your application.
- Use it to safely expand tuples into SQL IN clauses without manual string concatenation or SQL injection risk.
- Use it to convert batch operations (executemany) by formatting multiple parameter sets at once with formatmany().
- Use it to migrate code between database systems that prefer different parameter conventions (e.g., Oracle to SQL Server).
- Use it to strip SQL comments before parameter expansion to avoid accidentally matching variable-like strings in comments.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts SQL queries between different parameter styles (named, ordinal, numeric, and dollar-sign variants) to match what your database driver supports.
Yes. sqlparams solves a real compatibility problem with minimal friction: it's a pure-Python package with no dependencies, supports current Python versions (3.8–3.13), carries no known vulnerabilities, and uses a permissive MIT license. Its dormant maintenance status is not a concern for a stable utility with a narrow, well-defined scope. Install it if you need to bridge parameter style mismatches between your code and your database driver.
Install
sqlparams on PyPI
pip
pip install sqlparamsuv
uv add sqlparamspoetry
poetry add sqlparamsInstalling sqlparams
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is dormant (566 days since last release) but the repository remains active with a recent commit on 2025-01-25, and the package has been stable since its 2012 initial release.
License in practice
MIT License (permissive): you can use, modify, and distribute sqlparams freely in commercial and private projects with minimal restrictions.
Quickstart
import sqlparams
query = sqlparams.SQLParams('named', 'qmark')
sql, params = query.format('SELECT * FROM users WHERE name = :name;', {'name': 'Thorin'})
print(sql) # SELECT * FROM users WHERE name = ?;
print(params) # ['Thorin']
Verify before relying
- Whether the package handles all edge cases in parameter expansion (e.g., nested tuples, special characters in identifiers) as robustly as production use requires.
- Performance characteristics when converting large or complex queries with many parameters.
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 566 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,777,211/month — #1,851 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sqlparams-6.2.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
jinjasqlGenerates parameterized SQL queries from Jinja2…
permissive · top 15,000 on PyPI
pyodbcpyodbc provides Python access to ODBC databases…
permissive · top 1,000 on PyPI
python-sqlConstructs SQL queries programmatically using…
permissive · top 15,000 on PyPI
jinjasql2Generates parameterized SQL queries from Jinja2…
permissive · top 15,000 on PyPI
dbt-sqlserverA dbt adapter that enables data transformation…
permissive · top 15,000 on PyPI
buildpgbuildpg constructs PostgreSQL prepared…
permissive · top 15,000 on PyPI
mssqlWraps SQLAlchemy and pyodbc to simplify…
permissive · top 15,000 on PyPI
sqlalchemy-trinoProvides a SQLAlchemy dialect for connecting to…
permissive · top 15,000 on PyPI
pypyodbcpypyodbc provides a pure Python ODBC interface…
permissive · top 15,000 on PyPI
sqlmodelSQLModel combines SQLAlchemy and Pydantic to…
permissive · top 5,000 on PyPI