Quick Start
Get up and running with NLT in under five minutes. This guide covers installation, basic rendering, send suppression, and error handling.
Installation
Requires Python 3.10 or higher. NLT has zero third-party dependencies -- it uses only the Python standard library.
For development (adds pytest, ruff, mypy):
Basic Rendering
Create an NLTRenderer with your data, then call render() with subject and body templates:
RenderResult
The render() method returns a RenderResult dataclass with four fields:
In your email pipeline, always check suppressed before sending:
render_text() for Single Templates
When you need to render just one template string (not a subject/body pair), use render_text():
Returns None if a required expression suppresses the send:
Passing Event Data
NLT supports three data sources. You control what data the renderer can access through the constructor:
Contact Data
The contact dict holds user profile information. Flat keys are accessed in snake_case; keys under properties use original case first, then snake_case:
Trigger Event
The event that triggered the current flow. Must include event_name and attributes:
Additional Events
Named events beyond the trigger. Keyed by event name, each with an attributes dict:
Error Handling and Suppression
Smart Quote Handling
NLT automatically normalizes apostrophe-like characters before parsing. If a user pastes {the user\u2019s Name} from Google Docs (which uses smart quotes), or types {the user\u0060s Name} with a backtick, the tokenizer converts these to the standard ASCII apostrophe ' so the expression resolves correctly. Supported characters: \u2018 \u2019 \u201B (smart quotes), ` (backtick), \u00B4 (acute accent), \u02B9 \u02BC (modifier letters).
Graceful Degradation
NLT never throws on malformed templates. Unparseable expressions are left as literal text:
Send Suppression
The required modifier prevents sending an email with critical data missing:
If any required expression in either the subject or body resolves to null, the entire result is suppressed -- both html and subject are set to None.
Missing Data
When data is missing and not marked required, NLT returns an empty string by default. Use the or modifier to provide a fallback:
Use required for transactional data that must be present (order IDs, policy numbers). Use or "fallback" for personalization where a default is acceptable (names, preferences).
Next Steps
- Architecture -- understand the two-phase pipeline and security model
- Extension Points -- implement custom EventStore and TemplateLoader protocols
- API Reference: Tokenizer & Parser -- complete reference for all classes and functions