A Python templating library
Project description
choc-expr
A Python templating library
Why ChocExpr ?
ChocExpr is used by Chocolatine to help to generate SQL queries, but you are free to use it for your own projects.
Installation
pip install chocexpr
Functionnalities
- If-Then-Else statements (If test only with boolean actually)
- Line break
- Compact/Extended mode
- Attributes evaluation :
- Loop : unpack iterable and join it by a character separator
- Attribute chain : follow the chain and return the nested value
TODO
- Nested Conditions
- Methods (upper, lower, title, etc...)
- If condition resolution with an equality
- Optional parenthesis in loop statement
Examples
from choc_expr import Expr as ChocExpr
condition = True # or False
value_if_true = 1
value_if_false = 2
names = ("Kevin", "Sophia")
print(ChocExpr("@{condition}:{value_if_true} child is:{value_if_false} children (named $({names})) are;~playing football outside", vars()))
output :
>> 2 children (Kevin, Sophia) are
>> playing football outside
or
>> 1 child is
>> playing football outside
depending if condition is True or False.
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
choc_expr-1.0.tar.gz
(5.3 kB
view hashes)