Morphify
Lightweight string templating with safe variable resolution and value formatting.
Key features
- Simple
{{ ... }}expressions with function calls and string concatenation - Safe variable lookup with dot-paths (returns empty string on missing keys)
- Built-in helpers:
if(condition, then, else)andformat(value, pattern) - Value formatting for decimals and dates with human-friendly patterns
Installation
pip install morphify
Quick start
from morphify import TemplateMorpher
tpl = "Hello, {{ if($name, $name, 'guest') }}! Today is {{ format($date, 'DD.MM.YYYY') }}."
print(TemplateMorpher(tpl, {"name": "Alex", "date": "2025-10-05"}).render())
# -> Hello, Alex! Today is 05.10.2025.
API
from morphify import TemplateMorpher, ValueMorpher
-
TemplateMorpher(template: str, context: dict, config: TemplateConfig | None = None).render() -> str
- Replaces
{{ ... }}expressions withintemplateusing values fromcontext. - Supported features:
- Variables:
$user.name - Literals:
'text', "text" - Concatenation:
'A' + 'B' + $x - Functions:
if(condition, then, else)format(value, pattern)— pattern must be quoted
- Variables:
- Replaces
-
ValueMorpher(fmt: str, value: Any).render() -> str
- Automatically detects format type:
- Decimal: patterns like
0.00(precision is taken from the pattern) - Date: tokens like
DD,MM,YYYY,HH,mm,ss
- Decimal: patterns like
- Automatically detects format type:
Configuration
from morphify import TemplateMorpher
from morphify.morphify.template_morpher import TemplateConfig
tpl = 'Today: {{$date}}' # no explicit format()
cfg = TemplateConfig(default_date_format='DD/MM/YY')
print(TemplateMorpher(tpl, {"date": "2025-10-05"}, config=cfg).render())
# -> Today: 05/10/25
Formatting examples
from morphify import ValueMorpher
ValueMorpher('0.000', '3.14159').render() # '3.142'
ValueMorpher('DD/MM/YY HH:mm', 1728096000).render() # timestamp -> '05/10/25 00:00'
Testing
pytest -q
Coverage
The project uses coverage.py. Settings live in pyproject.toml.
- Run locally:
coverage run -m pytest -q && coverage report
CI integrates with Codecov. Provide CODECOV_TOKEN if required.
Contributing
- Run linters and tests before pushing:
uv sync --dev --locked
uv run pre-commit run --all-files
uv run pytest -q
License
MIT
Metadata
Release files for morphify 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| morphify-0.1.2.tar.gz | 42.7 kB | Without provenance | Details for morphify-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| morphify-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for morphify-0.1.2-py3-none-any.whl |
Total release size: 49.1 kB
Release files / morphify-0.1.2.tar.gz
| Download URL | morphify-0.1.2.tar.gz |
|---|---|
| Size | 42.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17e96b2e1fb5a2f68e109ee55b9b2856fc0ed23fec5cc172b2f7739d4e248dc3
|
|
BLAKE2b-256 checksum How to use checksums |
88a5431b12b515b6d775429d52d5154b163d4be71bea5309110401e58d252fd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|
Release files / morphify-0.1.2-py3-none-any.whl
| Download URL | morphify-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e168cf738aef822ebe9e68efa69012814db1832a12bf63aa56d88eb8e5456477
|
|
BLAKE2b-256 checksum How to use checksums |
a6188e861ccf78e732d400d786bcab3dccd265e4fd1671ca066f9a76fb271510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.23
|
Security for morphify 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.