High-level Python API#
tattler comes with an open-source python SDK.
The high-level API in it allows you to trigger a notification with one line of code:
# high-level API
from tattler.client.tattler_py import send_notification
success, details = send_notification('mywebapp', 'password_changed', 'your@email.com', {'var1': 1, 'var2': 'two'}, correlationId='1234')
if not success:
print(details)
Here you notice additional parameters:
A client context: a dictionary containing variable definitions, which tattler will pass on to the template.
A correlationId: a string identifying the transaction at the client, which tattler will log into its own logs to aid cross-system troubleshooting.
Here’s a brief reference of the function:
Python client to access tattler server
- tattler.client.tattler_py.send_notification(scope, event, recipient, context=None, correlationId=None, mode='debug', vectors=None, priority=None, srv_addr='127.0.0.1', srv_port=11503)#
All-in-one utility to connect to tattler server and send a notification.
- Parameters:
scope (
str
) – The scope name to search the event in.event (
str
) – The event name to deliver.context (
Optional
[Mapping
[str
,str
]]) – Optional custom variables (name:value) to use for template expansion.correlationId (
Optional
[str
]) – correlation ID for tattler log when processing this request. Self-generated if missing.mode (
str
) – Notification mode in ‘debug’, ‘staging’, ‘production’.vectors (
Optional
[Iterable
[str
]]) – Restrict delivery to these vectors; ‘None’ delivers to all vectors declared by the event template.priority (
Optional
[bool
]) – Embed this user-visible priority in the notification, where the vector supports it.srv_addr (
Optional
[str
]) – Contact tattler_server at this IP address. Default: 127.0.0.1srv_port (
Optional
[int
]) – Contact tattler_server at this port number. Default: 11503
- Return type:
Tuple
[bool
,Optional
[Mapping
[str
,str
]]]- Returns:
Whether delivery succeeded for at least one vector, and delivery details for all.
Additionally, the python client is controlled by the following environment variables:
LOG_LEVEL
Values:
debug
,info
,warning
,error
.Default:
info
.Only log entries at or higher than this severity.