jinjasql
Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template
What it is and what it does
JinjaSQL bridges Jinja2 templating and SQL generation, letting you write dynamic SQL queries using Jinja's full feature set—conditionals, loops, macros—while automatically extracting and binding parameters to prevent SQL injection. Instead of executing queries directly, it returns a parameterized query string (with %s, ?, :1, or other placeholders depending on your database driver) and a corresponding list or dictionary of bind values, which you then execute using your own database connection.
The package is designed for reporting, business intelligence, and complex queries where an ORM falls short—aggregations, multi-table joins, and bulk operations with dynamic structure. It does not execute queries itself; you retain full control over the database driver and execution. It automatically applies the bind filter to all template variables to catch injection risks at template-compile time, and provides optional filters like `|inclause` for IN clauses and `|sqlsafe` for table/column names when you explicitly need dynamic SQL identifiers.
Use it for:
- Build dynamic reporting queries with conditional WHERE clauses based on user filters
- Generate aggregation and GROUP BY queries that vary in structure depending on parameters
- Create migration or bulk-update scripts using Jinja macros to reduce repetition
- Support multi-table joins with optional conditions that an ORM cannot express as cleanly
- Generate parameterized queries for multiple database drivers (PostgreSQL, MySQL, SQLite) using different placeholder styles
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates parameterized SQL queries from Jinja2 templates, automatically binding variables to prevent SQL injection while supporting multiple parameter styles.
Yes, if you need dynamic SQL templating with injection protection and your project can tolerate a dormant package. The core functionality is stable and the single Jinja2 dependency is mature. Not recommended if you require active maintenance, ongoing security updates, or support for cutting-edge Python versions—use an ORM or a maintained query builder instead for those cases.
Install
jinjasql on PyPI
pip
pip install jinjasqluv
uv add jinjasqlpoetry
poetry add jinjasqlInstalling jinjasql
Before you install
Low friction installation with a single runtime dependency on Jinja2. However, the package is dormant—last release was 2020-05-27, over four years ago, with no recent commits despite the repository remaining active. Suitable for stable use cases but not for projects requiring ongoing maintenance or updates.
License in practice
MIT license is permissive and imposes no restrictions on use, modification, or distribution. Safe for commercial and private projects.
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 = %s"
# bind_params: [123]
Verify before relying
- Whether the package works reliably with modern Jinja2 versions beyond those listed in the description
- Current compatibility with Python versions released after 3.5, given the classifiers list only mentions up to 3.5
- Whether dormancy affects real-world usage or if the stable API is sufficient for typical reporting/BI workflows
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Jinja2 |
| Maintenance | dormant — 2,270 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 628,046/month — #5,678 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: jinjasql-0.1.8-py3-none-any.whl
Keywords: Jinja2, SQL, Python, Template
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
jinjasql2Generates parameterized SQL queries from Jinja2…
permissive · top 15,000 on PyPI
sqlparamsConverts SQL queries between different…
permissive · top 5,000 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
sqlfluffSQLFluff is a SQL linter and auto-fixer that…
permissive · top 5,000 on PyPI
jinja_partialsAdds a `render_partial()` function to Jinja2…
permissive · top 5,000 on PyPI
buildpgbuildpg constructs PostgreSQL prepared…
permissive · top 15,000 on PyPI
j2lintj2lint validates Jinja2 template syntax and…
permissive · top 15,000 on PyPI
jinja2_pluralizeProvides Jinja2 template filters for…
permissive · top 15,000 on PyPI
jinja-cliA command-line tool that renders Jinja2…
copyleft · top 15,000 on PyPI
django-query-builderBuilds and executes complex SQL queries…
permissive · top 15,000 on PyPI