Skip to content

pe-brian/choc-expr

Repository files navigation

PyPI version Licence badge Python Actions Status Dependencies Downloads per month Last commit

choc-expr

Image

A mini 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 choc-expr

Functionnalities

  • If-Then-Else statements
  • 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...)
  • Optional parenthesis in loop statement

Examples

from choc_expr import Expr as ChocExpr

age = 24  # or 15
print(ChocExpr("Kevin is @{age}>=18:an adult:a child; of {age} years old", vars()))

output :

>> Kevin is an adult of 24 years old

or

>> Kevin is a child of 15 years old

depending if condition is True or False.