Low-level Python API

Use this API if you need fine-grained control of notifications, for example if you want to send a large number of notifications in one go and want to reuse the HTTP connection.

from tattler.client.tattler_py import TattlerClientHTTP

# refer to templates in folder template_base/my_application. Debug mode = only send to test address, not to actual recipient
n = TattlerClientHTTP(scope_name='myapplication', srv_addr='127.0.0.1', srv_port=11503, mode='debug')
# send notification for event 'my_event' over email only to user #20 (tattler resolves actual email address)
n.send(vectors=['email'], event='my_event', recipient='20')

# send template which requires expanding variables
n.send(vectors=['email'], event='my_event', recipient='20', context={'var1': 'value1', 'var2': 'value2'})

# set priority flag, and use correlationID to associate throughout delivery chain
n.send(vectors=['email'], event='my_event', recipient='20', priority=True, correlationId='12398724')

# utility to generate correlationIds
from tattler.client.tattler_py import mk_correlation_id
print(mk_correlation_id())
# NkvgXrYI

TattlerClient

tattler.client.tattler_py.TattlerClientHTTP is the concrete HTTP-based implementation of the interface tattler.client.tattler_py.TattlerClient, and leverages the REST endpoint of tattler server.

class tattler.client.tattler_py.TattlerClientHTTP(scope_name, srv_addr='127.0.0.1', srv_port=11503, mode='debug')

HTTP implementation of TattlerClient

class tattler.client.tattler_py.TattlerClient(scope_name, srv_addr='127.0.0.1', srv_port=11503, mode='debug')

Connection controller class to access tattler server functionality.

__init__(scope_name, srv_addr='127.0.0.1', srv_port=11503, mode='debug')

Construct TattlerClient.

Parameters:
  • scope_name (str) – Name of the scope to use when sending requests to server.

  • srv_addr (str) – IP address to connect to for tattler_server.

  • srv_port (int) – Port number to connect to for tattler_server.

  • mode (str) – Operating mode to request when sending requests to server.

events()

Return list of available events within this scope.

Return type:

Optional[Iterable[str]]

Returns:

List of events available within my scope, or None if unknown.

scopes()

Return list of scopes available at this server.

Return type:

Optional[Iterable[str]]

vectors(event)

Return list of vectors available vectors within this scope.

Parameters:

event (str) – Name of event to check available vectors for.

Return type:

Optional[Iterable[str]]

Returns:

List of vectors available for the event within my scope, or None if unknown.

Correlation IDs

If you pass a correlationId to notification calls, tattler will include that string in all log messages relevant to that call. This is purely optional, and enables you to trace a user or session across multiple subsystems of your overall service.

A correlationId is any string – but preferably a unique one. You may choose to prefix this string with the name of the subsystem where the session you want to track has originated.

Tattler offers the mk_correlation_id() symbol for that:

tattler.client.tattler_py.mk_correlation_id(prefix='tattler')

Generate a random correlation ID, for sessions where none has been pre-provided.

Parameters:

prefix (Optional[str]) – Optional string to prepend to the returned random ID (‘prefix:id’); set to None for no string (‘prefix’).

Return type:

str

Returns:

Random ID suitable for correlation logging, potentially prefixed with given prefix.