Skip to main content

Jinja Templates to SQL

Project description

Jinja2SQL (Jinja To SQL)

Jinja2SQL is a simple and efficient library for generating SQL queries from Jinja2 templates. It is type-friendly and offers async support, drawing significant inspiration from the excellent library at jinjasql.

CI codecov Documentation Status Code style: black


Documentation

http://jinja2sql.readthedocs.io/


Requirements

Python 3.8+ and Jinja2 3.1.2+.

Installation

Install using pip:

pip install jinja2sql

or using poetry:

poetry add jinja2sql

Quick Example

from jinja2sql import Jinja2SQL


j2sql = Jinja2SQL(param_style="named")

query, params = j2sql.from_string(
    "SELECT * FROM {{ table | identifier }} WHERE email = {{ email }}",
    context={"table": "users", "email": "user@mail.com"},
)


assert query == "SELECT * FROM users WHERE email = :email"
assert params == {"email": "user@mail.com"}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja2sql-0.1.0.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

jinja2sql-0.1.0-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page