Preview: SendMock has no stable release yet. These docs follow develop.
SendMock
Reference

Template filters

Every filter you can use in webhook templates, provider definitions and gateway templates.

Generated from SendMock's code, so it always matches the binary.

Templates use Jinja syntax: {{ data.subject | truncate(20) }} passes the value through a filter, and filters chain from left to right. See Templates and Variables for what a template can read.

SendMock's filters

FilterUsageWhat it gives
defaultvalue | default(fallback)The fallback when the value is missing, null or empty.
dvalue | d(fallback)Short for default.
requiredvalue | required(message)Stops the render with the message when the value is missing, null or empty.
capitalizetext | capitalizeThe first character in upper case and the rest in lower case.
squishtext | squishEvery run of whitespace collapsed into one space, with the ends trimmed.
truncatetext | truncate(length, end="...")The first length characters, followed by end when the text was cut.
slicevalue | slice(start, end)Characters or list items from start up to end (excluded); negative indexes count from the end.
regex_replacetext | regex_replace(pattern, replacement)Every match of the regular expression replaced; $1 or ${name} in the replacement inserts a capture.
regex_extracttext | regex_extract(pattern, group)The match of the regular expression, or its capture group; empty when nothing matches.
containsvalue | contains(item)Whether a text contains a piece of text, or a list contains an item.
slugifytext | slugifyLowercase ASCII words joined by -: Hello, World! becomes hello-world.
pad_lefttext | pad_left(width, character)The text padded on the left to width characters, with spaces or the given character.
pad_righttext | pad_right(width, character)The text padded on the right to width characters, with spaces or the given character.
number_formatnumber | number_format(decimals)The number with decimals places and , between thousands: 1234.5 becomes 1,234.50.
datetime | date(format, tz="UTC")The time written with a strftime format (default %Y-%m-%dT%H:%M:%SZ) in a time zone (default UTC).
date_addtime | date_add(seconds)The time seconds later, or earlier when negative, as an RFC 3339 timestamp.
unixtime | unixThe time as Unix seconds.
e164phone | e164The number without spaces, dashes, dots or brackets, a leading 00 turned into +.
phone_countryphone | phone_countryThe ISO country code of an international number, or an empty string.
phone_nationalphone | phone_nationalThe digits after the calling code, or every digit when the country is unknown.
urlencodevalue | urlencodePercent-encoded as JavaScript's encodeURIComponent does.
base64_encodevalue | base64_encodeThe text encoded as standard Base64.
base64_decodetext | base64_decodeStandard Base64 decoded back to text.
hex_encodevalue | hex_encodeThe text's bytes as lowercase hexadecimal.
escape_htmlvalue | escape_html&, <, >, " and ' escaped for HTML.
strip_htmlvalue | strip_htmlThe text with HTML tags removed.
jsonvalue | jsonThe value as indented JSON, written as it is even inside a JSON string.
tojsonvalue | tojsonThe value as compact JSON (a string gets its quotes), written as it is.
fromjsontext | fromjsonJSON text parsed into a value, so its fields can be read.
pickobject | pick("key", ...)The object with only the named keys.
omitobject | omit("key", ...)The object without the named keys.
md5value | md5The MD5 digest as lowercase hexadecimal.
sha1value | sha1The SHA-1 digest as lowercase hexadecimal.
sha256value | sha256The SHA-256 digest as lowercase hexadecimal.
sha512value | sha512The SHA-512 digest as lowercase hexadecimal.
hmac_sha256value | hmac_sha256(key, encoding="hex")The HMAC-SHA256 of the value with the key, as hex (default) or base64, for provider signatures.
hmac_sha1value | hmac_sha1(key, encoding="hex")The HMAC-SHA1 of the value with the key, as hex (default) or base64.
sendgrid_eventevent.type | sendgrid_eventSendGrid's name for an email event, such as bounce for email.bounced.
ses_typeevent.type | ses_typeAmazon SES's notification type for an email event, such as Bounce.
resend_typeevent.type | resend_typeResend's event type for an email event, such as email.bounced.
mailgun_eventevent.type | mailgun_eventMailgun's event name for an email event, such as failed.
postmark_record_typeevent.type | postmark_record_typePostmark's record type for an email event, such as Bounce.
brevo_eventevent.type | brevo_eventBrevo's event name for an email event, such as hard_bounce.
payment_eventevent.type | payment_event("stripe")The payment provider's name for a payment event, or the native name when it has none.

Jinja's built-in filters

These come from the template engine, minijinja, and work as they do in Jinja: upper, lower, title, trim, length, count, first, last, replace, join, map, unique, sort, reverse, round, abs, int, float, string, list, items, dictsort, select, reject, selectattr, rejectattr, sum, min, max, split, lines, indent, attr, groupby, chain, zip, format, bool, escape, e, safe, batch.

On this page