Message

Classes:

Message([msg, expand_arrays])

A formatted message.

class Message(msg=None, expand_arrays=False, **kwargs)[source]

Bases: object

A formatted message.

id, to, sender, and key are required attributes, but any other key-value pair passed on init is added to the message’s attributes and included in the message.

Can be indexed and set like a dictionary (message[‘key’], etc.)

Variables
  • id (str) – ID that uniquely identifies a message. format {sender.id}_{number}

  • to (str) – ID of socket this message is addressed to

  • sender (str) – ID of socket where this message originates

  • key (str) – Type of message, used to select a listen method to process it

  • value – Body of message, can be any type but must be JSON serializable.

  • timestamp (str) – Timestamp of message creation

  • ttl (int) – Time-To-Live, each message is sent this many times at max, each send decrements ttl.

Parameters
  • *args

  • **kwargs

Attributes:

id

to

sender

key

value

changed

flags

timestamp

ttl

serialized

Methods:

__getitem__(key)

Parameters

key

__setitem__(key, value)

Parameters
  • key

_serialize_numpy(array)

Serialize a numpy array for sending over the wire

expand()

Don’t decompress numpy arrays by default for faster IO, explicitly expand them when needed

__delitem__(key)

Parameters

key

__contains__(key)

Parameters

key

get_timestamp()

Get a Python timestamp

validate()

Checks if id, to, sender, and key are all defined.

serialize()

Serializes all attributes in __dict__ using json.

id = None
to = None
sender = None
key = None
value = None
changed = False
flags = {}
timestamp = None
ttl = 2
serialized = None
__getitem__(key)[source]
Parameters

key

__setitem__(key, value)[source]
Parameters
  • key

  • value

_serialize_numpy(array)[source]

Serialize a numpy array for sending over the wire

Parameters

array

Returns:

expand()[source]

Don’t decompress numpy arrays by default for faster IO, explicitly expand them when needed

Returns

__delitem__(key)[source]
Parameters

key

__contains__(key)[source]
Parameters

key

get_timestamp()[source]

Get a Python timestamp

Returns

Isoformatted timestamp from datetime

Return type

str

validate()[source]

Checks if id, to, sender, and key are all defined.

Returns

Does message have all required attributes set?

Return type

bool (True)

serialize()[source]

Serializes all attributes in __dict__ using json.

Returns

JSON serialized message.

Return type

str