jinjasql2
Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template
Decision gist · record as of 2026-08-14
Yes, if you need to generate dynamic SQL queries safely in Python and your use case genuinely requires raw SQL (reporting, complex aggregations, bulk operations). The package is lightweight, actively maintained, has no known vulnerabilities, and supports modern Python versions. Not necessary if an ORM handles your queries adequately.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with only Jinja2 as a runtime dependency.
- Actively maintained with a recent release and no known vulnerabilities.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
last release 2026-07-07 (38 days) · last repo commit 2026-07-07 · 45 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 142,297 downloads/mo, #11,214 on PyPI
Alternatives
Verify before relying
from jinjasql import JinjaSql
j = JinjaSql()
template = "SELECT * FROM users WHERE id = {{ user_id }}"
query, bind_params = j.prepare_query(template, {"user_id": 123})
# query: "SELECT * FROM users WHERE id = :user_id_1"
# bind_params: {"user_id_1": 123}- Performance characteristics when handling large or deeply nested template contexts
- Compatibility with specific database drivers beyond the examples given (Django, asyncpg)
What it is and what it does
JinjaSQL is a template engine that generates parameterized SQL queries from Jinja2 templates. It processes template variables and conditional logic, then outputs a query with placeholders and a separate dictionary or tuple of bind parameters, ensuring values are never inlined into the SQL string itself. The package supports multiple parameter styles (named, format, qmark, numeric, pyformat, asyncpg) to match different database drivers' conventions.
The package is designed for scenarios where raw SQL is necessary—reporting, aggregation, bulk migrations, and multi-table queries—rather than as an ORM replacement. It protects against SQL injection by binding all template variables as parameters, though templates themselves must be trusted code (the sqlsafe and identifier filters allow deliberate inlining when needed). You prepare the query and parameters, then execute them using your database driver of choice.
Use it for
- Build dynamic reporting queries with conditional WHERE clauses, GROUP BY, and aggregations that an ORM cannot express cleanly
- Generate parameterized bulk update or migration scripts using Jinja macros and loops while maintaining SQL injection safety
- Construct multi-table SELECT queries with optional joins and filters based on runtime conditions
- Support IN clauses with the inclause filter to bind list elements as separate parameters for database drivers
- Escape table and column names safely using the identifier filter when dynamic schema references are required
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need to generate dynamic SQL queries safely in Python and your use case genuinely requires raw SQL (reporting, complex aggregations, bulk operations).
The package is lightweight, actively maintained, has no known vulnerabilities, and supports modern Python versions. Not necessary if an ORM handles your queries adequately.
Install
jinjasql2 on PyPI
Before you install
Low friction: pure Python wheel with only Jinja2 as a runtime dependency. Actively maintained with a recent release and no known vulnerabilities.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
Quickstart
from jinjasql import JinjaSql
j = JinjaSql()
template = "SELECT * FROM users WHERE id = {{ user_id }}"
query, bind_params = j.prepare_query(template, {"user_id": 123})
# query: "SELECT * FROM users WHERE id = :user_id_1"
# bind_params: {"user_id_1": 123}
Verify before relying
- Performance characteristics when handling large or deeply nested template contexts
- Compatibility with specific database drivers beyond the examples given (Django, asyncpg)
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packageJinja2 |
| Maintenance | Actively maintained 38 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 142,297 / month, #11,214 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: jinjasql2-0.1.13-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “jinja sql template generation”
- jinjasql2Generates parameterized SQL queries from Jinja2 templates,…
- jinjasqlGenerates parameterized SQL queries from Jinja2 templates,…
- sphinx-jinjaA Sphinx extension that lets you embed Jinja2 templates directly into…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also jinjasql · Jinja2 · sqlvalidator · sqlparams · sqlfluff · buildpg · sqlfluff-templater-dbt · jinja_partials · mkdocs-macros-plugin · python-sql