A Python package for filling template strings with combinations of provided variables. This tool is useful for generating multiple variations of text based on a single template and a set of possible variable values.
To install template_filler, use pip:
pip install template_fillerThe fill_template function takes a template string and a list of dictionaries. Each dictionary specifies a variable name and a list of its possible values. The function returns a list of strings, where each string is a unique combination of the template filled with the provided variable values.
from template_filler import fill_template
template = "Hello, ${name}! Your age is ${age}."
vars_data = [
{"name": ["Alice", "Bob"]},
{"age": [30, 25]}
]
results = fill_template(template, vars_data)
# The 'results' list will contain:
# [
# "Hello, Alice! Your age is 30.",
# "Hello, Alice! Your age is 25.",
# "Hello, Bob! Your age is 30.",
# "Hello, Bob! Your age is 25."
# ]
for res in results:
print(res)- Combinatorial Filling: Generates all possible combinations of provided variable values.
- String Templates: Utilizes Python's
string.Templatefor straightforward placeholder syntax (e.g.,${variable_name}). - Type Flexibility: Handles various data types for variable values, converting them to strings for substitution.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
template_filler is licensed under the MIT License.