A simple library for replacing value placeholders in template texts/files.
Note that this is a library for development/testing tools, so the performance is not a primary concern.
This chapter describes all supported placeholders that can be used in template files.
${random.uuid}- replace with a random UUID value.${random.int(min, max)}- replace with a random integer within the specified range.${random.double(min, max)}- replace with a random double (floating-point number) within the specified range.${random.boolean}- replace with a random boolean value (trueorfalse).${random.string(size)}- replace with a random string of the given size.${random.choice(a, b, ...)}- replace with a random choice from the provided arguments. Arguments may be single-word unquoted, or quoted ('or").${random.date(start, end)}- replace with a random date (format:YYYY-MM-DD) betweenstartandend. Dates may be quoted or unquoted and can be ISO dates or epoch seconds.${random.datetime(start, end)}- replace with a random datetime (format:YYYY-MM-DDTHH:MM:SS) betweenstartandend. Datetimes may be quoted or unquoted and can be ISO datetimes or epoch seconds.${random.timestamp}- replace with the current Unix timestamp (seconds since epoch).${random.date.past(days=N)}- replace with a random date within the pastNdays (inclusive).${random.date.future(days=N)}- replace with a random date within the nextNdays (inclusive).
- Using Poetry:
$ poetry add git+https://github.com/malczuuu/pytemple.git#1.1.0
- Using Pipenv:
$ pipenv install git+https://github.com/malczuuu/pytemple@1.1.0#egg=pytemple
import pytemple
with open("template.txt") as file:
template = file.read()
template = pytemple.loads(template)Following template
{
"uuid": "${random.uuid}",
"double": ${random.double(-10, 10)},
"integer": ${random.int(20, 30)},
"boolean": ${random.boolean},
"string": "${random.string(10)}"
}would be translated as
{
"uuid": "00772bf8-8f21-4f73-8ca0-30a5354cf935",
"double": -3.006947539966321,
"integer": 17,
"boolean": true,
"string": "cdtllavjhl"
}PyTemple is considered feature complete. Only bug fixes will be added. New features may be included only if there is a strong justification for them.