Modern and easy way to handle placeholders.
This package allows you to define text placeholders and process them dynamically. It's like str.format(), but gives you much more flexibility.
- Regular Expressions to find placeholders.
- Custom delimiters (
%var%,{var},${var}etc.). - Modern API using asyncio and decorators.
- Nested placeholders (
{greet_{name}}). - Type safety using annotations.
- No additional dependencies.
To install this module, run the following command:
pip install emplace
Example of creating a formatter with single placeholder.
from emplace import Formatter, placeholder
class MyFormatter(Formatter):
@placeholder(r"upper_(?P<text>.*)")
def upper_ph(self, text: str) -> str:
return text.upper()
formatter = MyFormatter()
result = await formatter.format("Hello, {upper_world}!")
print(result) # Hello, WORLD!You can check out more examples here.