skillfed

jinjasql

Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template

jinjasql v0.1.8 628.0K downloads/30d#5,678 on PyPI845
Permissive license MIT DORMANT released

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 jinjasql

uv

uv add jinjasql

poetry

poetry add jinjasql

Installing 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

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5

Tags

sql query templatingjinja2 sql generationsql injection preventionparameterized query builderdynamic sql templatesbind parameter generationtemplate-based sql
sql-templatinginjection-safereporting

More Database packages