Events

wishbone.event.Event object instances are used to store and transport structured data between module queues.

The input modules should initialize a wishbone.event.Event instance to encapsulate the data they receive or generate.

wishbone.event.Event is a simple class used for data representation including some convenience functions for data manipulation.

Examples

>>> from wishbone.event import Event
>>> e = Event("hi")
>>> e.dump()
{'@timestamp': '2015-12-13T10:45:35.442088+01:00', '@version': 1, '@data': 'hi'}
>>>

Initializing the Event objects assigns the data you pass to @data.

>>> e = Event("hi")
>>> e.get()
'hi'
>>>

By default, the get method returns @data.

>>> e = Event({"one": {"two": hi}})
>>> e.get('@data.one.two')
'hi'
>>>

Nested dictionaries can be accessed in dotted format.

>>> e = Event('hi')
>>> e.set("howdy", "one.two.three")
>>> e.get('one')
{'two': {'three': 'howdy'}}
>>>

New ‘root’ keys can be created outside @data. Setting nested dictionary values can be done using dotted format.

>>> e = Event('hello')
>>> e.dump(complete=True)
{'@timestamp': '2015-12-13T11:10:45.862036+01:00', '@tmp': {},
'@version': 1, '@data': 'hello', '@errors': {}}
>>>>
  • @tmp is where modules can optionally store temporary data which is not part of the data model but contain useful information for other modules.
  • The @errors key is where modules store exceptions related information.
class wishbone.event.Event(data=None)[source]

The Wishbone event object representation.

A class object containing the event data being passed from one Wishbone module to the other.

clone()[source]

Returns a cloned version of the event using deepcopy.

copy(source, destination)[source]

Copies the source key to the destination key.

Parameters:
  • source (str) – The name of the source key.
  • destination (str) – The name of the destination key.
deepish_copy(org)[source]

much, much faster than deepcopy, for a dict of the simple python types.

Blatantly ripped off from https://writeonly.wordpress.com/2009/05/07 /deepcopy-is-a-pig-for-simple-data/

delete(key=None)[source]

Deletes a key.

Parameters:key (str) – The name of the key to delete
dict_merge(dct, merge_dct)[source]

Recursive dict merge. Inspired by :meth:dict.update(), instead of updating only top-level keys, dict_merge recurses down into dicts nested to an arbitrary depth, updating keys. The merge_dct is merged into dct.

Stolen from https://gist.github.com/angstwad/bf22d1822c38a92ec0a9

Parameters:
  • dct – dict onto which the merge is executed
  • merge_dct – dct merged into dct
Returns:

None

dump(complete=False, convert_timestamp=True)[source]

Dumps the content of the event.

Parameters:
  • complete (bool) – Determines whether to include @tmp and @errors.
  • convert_timestamp (bool) – When True converts <Arrow> object to iso8601 string.
Returns:

The content of the event.

Return type:

dict

get(key='@data')[source]

Returns the value of <key>.

Parameters:key (str) – The name of the key to read.
Returns:The value of <key>
has(key='@data')[source]

Returns a boot indicating the event has <key>

Parameters:key (str) – The name of the key to check
Returns:Bool
raw(complete=False, convert_timestamp=True)

Dumps the content of the event.

Parameters:
  • complete (bool) – Determines whether to include @tmp and @errors.
  • convert_timestamp (bool) – When True converts <Arrow> object to iso8601 string.
Returns:

The content of the event.

Return type:

dict

set(value, key='@data')[source]

Sets the value of <key>.

Parameters:
  • value – The value to set.
  • key (str) – The name of the key to assign <value> to.