pyrx-nlt
Natural Language Template (NLT) Engine — Plain-English templates that non-technical teams can read, write, and maintain for email, notifications, and dynamic content.
Installation
pip install pyrx-nlt
Requires Python 3.10+. Zero third-party dependencies.
Quick Start
from pyrx_nlt import NLTRenderer
renderer = NLTRenderer(
contact={"first_name": "Alice", "properties": {"Plan": "premium", "Points": 1250}},
trigger_event={"event_name": "purchase", "attributes": {"Item": "Widget", "Amount": "49.99"}},
)
result = renderer.render(
subject_template='Order confirmation for {the user\'s First Name, or "Customer"}',
body_template="""
<h1>Thank you, {the user's First Name}!</h1>
<p>You purchased: {the Item from the trigger event}</p>
<p>Amount: {the Amount from the trigger event, as "currency"}</p>
{if the user's Plan is premium}
<p>You earned {the user's Points, as "currency"} in rewards!</p>
{else}
<p>Upgrade to Premium for rewards on every purchase.</p>
{end if}
""",
)
print(result.html) # Rendered HTML
print(result.subject) # "Order confirmation for Alice"
print(result.suppressed) # False
Features
- 3 data sources:
{the user's X},{the X from the trigger event},{the X from the Y event} - Modifiers:
or "fallback",required,as "format",uppercase/lowercase/titlecase - Math:
plus,minus,times,divided by,modulo - Conditionals:
{if}...{else if}...{else}...{end if}with 20 comparison operators, AND/OR/NOT - Loops:
{for item in source}...{end for}withloop.index,loop.first,loop.last - Lists:
{list source, as comma/ordered/unordered list} - Tables:
{table source with columns: A, B, C} - Aggregates:
{sum of},{average of},{count of} - 19 chainable filters:
truncate,replace,url_encode,round,default,strip_html,trim,newline_to_br,split,join,first,last,length,sort,reverse,unique,where,map,slice - Formatting: 17 currency codes, date presets, custom date tokens, percentages
- Variable assignment:
{set x to expression} - Ternary:
{condition ? "true" : "false"} - Comments:
{# ignored #} - Raw blocks:
{raw}...{end raw} - Macros:
{define name(params)}...{end define}/{use name(args)} - Template inheritance:
{extends "base.html"}/{block name}...{end block}/{parent} - Built-in variables:
{today},{now} - XSS-safe: All output HTML-escaped by default
- Graceful degradation: Unparseable expressions preserved as literal text
Extension Points
from pyrx_nlt import NLTRenderer, EventStore, TemplateLoader
class MyEventStore:
"""Implement to look up historical events for named event resolution."""
async def get_latest(self, contact_id: str, event_name: str) -> dict | None:
...
class MyTemplateLoader:
"""Implement for template inheritance ({extends "base.html"})."""
def load(self, template_name: str) -> str | None:
...
renderer = NLTRenderer(
contact=contact_data,
event_store=MyEventStore(),
template_loader=MyTemplateLoader(),
)
Jinja2 Migration
Built-in bidirectional converter for migrating from Jinja2/MoEngage templates:
from pyrx_nlt.converter import convert_jinja2_to_nlt, convert_nlt_to_jinja2, detect_template_language
nlt_template, result = convert_jinja2_to_nlt(jinja2_template)
print(f"Converted {result.count} expressions")
language = detect_template_language(template) # "nlt", "jinja2", "mixed", or "none"
License
MIT
Metadata
Release files for pyrx-nlt 1.3.0
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 | |
|---|---|---|---|---|
| pyrx_nlt-1.3.0.tar.gz | 233.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyrx_nlt-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 314.4 kB
Release files / pyrx_nlt-1.3.0.tar.gz
| Download URL | pyrx_nlt-1.3.0.tar.gz |
|---|---|
| Size | 233.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd1b061291eda1f2de6e8a43a068b9c878fc318a37233c791ef89977f218b9f4
|
|
BLAKE2b-256 checksum How to use checksums |
16fe1692f6c0b2c6bbb9d72824da5b9f6bf020300d58c92229d7b62687a580f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Release files / pyrx_nlt-1.3.0-py3-none-any.whl
| Download URL | pyrx_nlt-1.3.0-py3-none-any.whl |
|---|---|
| Size | 81.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9881df8cef0bef5cc493cd461e2e10ab8700a1ba97cac52e6f0e20a1962adcfc
|
|
BLAKE2b-256 checksum How to use checksums |
286333e640082dfb39db4880eae16b47b86c5a17e467086d75fc5d79ea960c1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Security for pyrx-nlt 1.3.0
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.