Skip to main content

A simple Python library for expanding template strings with optional groups and character sets.

Project description

PyPI version License: MIT Downloads LinkedIn

py_template_expander

A Python package that expands template strings with various placeholders including optional groups, alternatives, and character sets.

Installation

To install py_template_expander, use pip:

pip install py_template_expander

Usage

The expand function takes a template string and yields all possible expanded strings.

Here's a simple example:

from py_template_expander import expand

template1 = "Hello (world|there)!"
print("Expanding: ", template1)
for expansion in expand(template1):
    print(expansion)
# Expected output:
# Expanding:  Hello (world|there)!
# Hello world!
# Hello there!

template2 = "The quick [abc] fox."
print("\nExpanding: ", template2)
for expansion in expand(template2):
    print(expansion)
# Expected output:
# Expanding:  The quick [abc] fox.
# The quick a fox.
# The quick b fox.
# The quick c fox.

template3 = "Optional: (item1|item2) and (optional|)"
print("\nExpanding: ", template3)
for expansion in expand(template3):
    print(expansion)
# Expected output:
# Expanding:  Optional: (item1|item2) and (optional|)
# Optional: item1 and optional
# Optional: item1 and
# Optional: item2 and optional
# Optional: item2 and
# Optional:  and optional
# Optional:  and

Features

  • Optional Groups: Use (pattern) for parts that may or may not appear.
  • Alternatives: Use | within parentheses to specify choices, e.g., (A|B).
  • Character Sets: Use [abc] to match any single character within the brackets.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

py_template_expander is licensed under the MIT License.

Author

Eugene Evstafev

Repository

https://github.com/chigwell/py_template_expander

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

py_template_expander-2025.9.131516.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_template_expander-2025.9.131516-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file py_template_expander-2025.9.131516.tar.gz.

File metadata

File hashes

Hashes for py_template_expander-2025.9.131516.tar.gz
Algorithm Hash digest
SHA256 c6aa1f945e4a0b858a17c764636639310d6d9862576db5d5c6b0941c584a932c
MD5 7107e5f7d9fac6f8f8b65e6d3cf4fc90
BLAKE2b-256 7c021afaf34e9b0852b682d24632ee70c12db2ec771a8e4edfa990e90f820b03

See more details on using hashes here.

File details

Details for the file py_template_expander-2025.9.131516-py3-none-any.whl.

File metadata

File hashes

Hashes for py_template_expander-2025.9.131516-py3-none-any.whl
Algorithm Hash digest
SHA256 c622d73b0206ca62f401868f97e30127bf44996bc1e86d7d32134e7369e49b88
MD5 a62673105ea5513a13e63217e4f2e292
BLAKE2b-256 efc72c22638657bb591b196d768a98239403eeff7da4ecd47ba4d677c7af81bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page