--- id: jinjasql version: "0.1.8" license: MIT license_treatment: permissive maintenance: dormant --- # jinjasql — Generate SQL Queries and Corresponding Bind Parameters using a Jinja2 Template License: permissive · Maintenance: dormant · Downloads: 628.0K/mo ## 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 above — 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 pip install jinjasql uv add jinjasql 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 628.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags sql query templating, jinja2 sql generation, sql injection prevention, parameterized query builder, dynamic sql templates, bind parameter generation, template-based sql, sql-templating, injection-safe, reporting [View on SkillFed](https://skillfed.io/packages/jinjasql) · [View on PyPI](https://pypi.org/project/jinjasql/)