Python API

class statetip.StateTipSender(host='localhost', port=3012)

Sender client class.

Parameters:
  • host – address of StateTip instance to send events to
  • port – sender port of StateTip instance
Throws :

NetworkError

send(name, origin, key, related=False, state=None, severity=None, info=None, sort_key=None, created=None, expiry=None)
Parameters:
  • name (string) – value group name
  • origin (string or None) – value group’s origin
  • key (string) – value’s key
  • sort_key (string or None) – key to sort values with when reading
  • related (boolean) – value group type, i.e. if it’s a group of related or unrelated values
  • state (string or None) – state to store in this value
  • severity ("expected", "warning", or "error") – severity of the state
  • info (JSON-serializable object) – additional data to store in this value
  • created (integer or float) – timestamp (unix) of collection of this value
  • expiry (integer (seconds)) – when this value expires after its collection
Throws :

NetworkError, ValueError

Send an event to StateTip.

If any of the fields is not serializable, ValueError exception is raised. Network errors are signaled by throwing NetworkError.

See Glossary for exact meaning of any of the above terms.

class statetip.StateTipReader(host='localhost', port=3082, timeout=None)

Reader client class.

Parameters:
  • host – address of StateTip instance to send events to
  • port – sender port of StateTip instance
  • timeout – request timeout for reading data
get(name, origin, key)
Parameters:
  • name (string) – value group name
  • origin (string or None) – value group’s origin
  • key (string) – value’s key
Returns:

dictionary or None

Throws :

AddressError, NetworkError, Timeout, ValueError

Retrieve a specific value (or None if value doesn’t exist). Returned value will similar to the following dictionary:

{"name": "cpus", "origin": "web01", "key": "cpu0",
    "state": None, "severity": "expected", "info": None}

The returned dictionary is guaranteed to have following fields:

  • "name" – value group’s name (string)
  • "origin" – value group’s origin (string or None)
  • "key" – value’s key (string)
  • "state" – state recorded in the value (string or None)
  • "severity" – state severity ("expected", "warning", or "error")
  • "info" – additional information recorded in the value

Invalid group name or origin results in ValueError.

keys(name, origin)
Parameters:
  • name (string) – value group name
  • origin (string or None) – value group’s origin
Returns:

list of keys (strings)

Throws :

AddressError, NetworkError, Timeout, ValueError

List keys for a specific origin in a value group.

Invalid group name or origin results in ValueError.

names()
Returns:list of names (strings)
Throws :AddressError, NetworkError, Timeout

List the names of recorded value groups.

origins(name)
Parameters:name (string) – value group name
Returns:list of origins (strings, with one entry possibly being None)
Throws :AddressError, NetworkError, Timeout, ValueError

List origins for a specific value group.

Invalid group name results in ValueError.

values(name, origin)
Parameters:
  • name (string) – value group name
  • origin (string or None) – value group’s origin
Returns:

list of dictionaries, each of the same format as get()

Throws :

AddressError, NetworkError, Timeout, ValueError

List all values (including key, state, severity, and info fields) of a specific origin in a value group.

Invalid group name or origin results in ValueError.

exception statetip.StateTipException

A base class for exceptions.

exception statetip.AddressError

StateTip address (host or port) invalid exception.

exception statetip.NetworkError

Network error exception.

exception statetip.HTTPError(code, reason)

HTTP error exception, a subclass of NetworkError.

Parameters:
  • code – HTTP status code
  • reason – message returned in status line

Both parameters are available as exception’s fields (e.code and e.reason, respectively).

exception statetip.Timeout

Request timeout exception.

Previous topic

StateTip daemon

Next topic

Client protocols

This Page