jinja-comprehensions
Jinja2 environments providing support for list/dict comprehensions, set literals/comprehensions, generator expressions, and list/dict spreading.
Set literals
{{ {'set', 'set', 'literal', 'literal'} }}
{'literal', 'set'}
Comprehensions
list: {{ [n // 2 for n in range(10)] }}
set: {{ {n // 2 for n in range(10)} }}
dict: {{ {n: n // 2 for n in range(10)} }}
list: [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
set: {0, 1, 2, 3, 4}
dict: {0: 0, 1: 0, 2: 1, 3: 1, 4: 2, 5: 2, 6: 3, 7: 3, 8: 4, 9: 4}
Generator expressions
{{ (n // 2 for n in range(10)) | join(', ') }}
0, 0, 1, 1, 2, 2, 3, 3, 4, 4
List/dict spreading
{% set stuff = {'b': 98, 'c': 99, 'd': 100} -%}
{{ {'a': 97, **stuff, 'e': 101} }}
{{ [97, *stuff.values(), 101] }}
{'a': 97, 'b': 98, 'c': 99, 'd': 100, 'e': 101}
[97, 98, 99, 100, 101]
Environments are provided for both sync and async contexts, as well as native variants, too.
Quickstart
pip install jinja-comprehensions
And use a ComprehensionEnvironment (or NativeComprehensionEnvironment) instead of the vanilla jinja2.Environment to compile your templates:
# For rendering to strings
from jinja_comprehensions import ComprehensionEnvironment
jinja_env = ComprehensionEnvironment()
# For rendering to native types
from jinja_comprehensions import NativeComprehensionEnvironment
jinja_env = NativeComprehensionEnvironment()
# For rendering to native types with async enabled
# (This env avoids some pitfalls with vanilla Jinja2 native envs and Awaitable return values)
from jinja_comprehensions import NoLiteralEvalComprehensionNativeEnvironment
jinja_env = NoLiteralEvalComprehensionNativeEnvironment()
Metadata
Release files for jinja-comprehensions 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jinja_comprehensions-0.1.1.tar.gz | 12.5 kB | Without provenance | Details for jinja_comprehensions-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jinja_comprehensions-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for jinja_comprehensions-0.1.1-py3-none-any.whl |
Total release size: 23.9 kB
Release files / jinja_comprehensions-0.1.1.tar.gz
| Download URL | jinja_comprehensions-0.1.1.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ac83c7f6a05d672ba0e6fe82739316635ca5a0198b1f00f85c026a92c480cdc
|
|
BLAKE2b-256 checksum How to use checksums |
080c9428d39d2c336d7dc78dbefece48189f0b6a38611acb180d87587fb738e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.4 Linux/5.13.0-52-generic
|
Release files / jinja_comprehensions-0.1.1-py3-none-any.whl
| Download URL | jinja_comprehensions-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95609794d35ccbbfe8b60c8f687ca38b8b12b0899e69fb059da63022b2160ef4
|
|
BLAKE2b-256 checksum How to use checksums |
8cd6282bcdf4acc2eed40245da036df4ddd09f67f4e26942553bdfcce4970113
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.4 Linux/5.13.0-52-generic
|
Security for jinja-comprehensions 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.