Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.28 KB

File metadata and controls

40 lines (32 loc) · 1.28 KB

pypi python codecov

emplace

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.

Features

  • 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.

Installation

To install this module, run the following command:

pip install emplace

Usage

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!

Examples

You can check out more examples here.