Event

class wishbone.event.Event(data=None, ttl=254, bulk=False, bulk_size=100)[source]

The Wishbone event object.

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

The keyformat used is the one handled by the Scalpl module (https://pypi.python.org/pypi/scalpl/).

Parameters:
  • data – The data to assign to the data field.
  • ttl – The TTL value for the event.
  • bulk – Initialize the event as a bulk event
  • bulk_size – The number of events the bulk can hold.
data

dict – A dict containing the event data structure.

bulk_size

int – The max allowed bulk size.

appendBulk(event)[source]

Appends an event to this bulk event.

Parameters:event – The event to add to the bulk instance
Raises:InvalidData – Either the event is not of type Bulk or event is not an wishbone.event.Event instance.
clone()[source]

Returns a cloned version of the event.

Returns:A ``wishbone.event.Event`` instance
Return type:class
copy(source, destination)[source]

Copies the source key to the destination key.

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

Decrements the TTL value.

Raises:TTLExpired – When TTL has reached 0.
delete(key=None)[source]

Deletes a key.

Parameters:

key – The key to delete

Raises:
  • Exception – Deleting the root of a reserved keyword such as data or tags.
  • KeyError – When a non-existing key is referred to.
dump()[source]

Dumps the complete event. This complete event is also called a native event

Returns:The content of the event.
Return type:dict
get(key='data')[source]

Returns the value of key.

key must be in Scalpl format.

Parameters:key – The name of the key to read.
Returns:The value of the key
Return type:str/int/float/dict/list
Raises:KeyError – The provided key does not exist.
getNative()

Dumps the complete event. This complete event is also called a native event

Returns:The content of the event.
Return type:dict
has(key='data')[source]

Returns a bool indicating the event has key

key must be in Scalpl format.

Parameters:key – The name of the key to check
Returns:True if the key is there otherwise false
Return type:bool
Raises:KeyError – The provided key does not exist
isBulk()[source]

Tells whether event is bulk or not.

Returns:True if the event is bulk
Return type:bool
merge(value, key='data')[source]

Merges value into key. Value types should be mergeable otherwise an error is returned.

Parameters:
  • value – The value to merge
  • key – The key to merge into
Raises:

InvalidData – Types are not mergeable

raw()

Dumps the complete event. This complete event is also called a native event

Returns:The content of the event.
Return type:dict
render(template, env_template=None)[source]

Returns a formatted string using the provided template and key

Parameters:
  • template – A string representing the Jinja2 template.
  • env_template – Used to render template strings from. If not set, then template rendering happens without environment.
Returns:

The rendered string

Return type:

str

Raises:

InvalidData – An invalid jinja2 template has been provided

renderField(field_name, env_template=None)[source]

Expects field_name to contain a template, renders it and replaces its content with the result. If the field field_name contains anything else than a string then it’s silently ignored.

Parameters:field_name – A string defining the field to handle.
Returns:None
Raises:InvalidData – An invalid jinja2 template has been provided
renderKwargs(template_kwargs)[source]

Renders all the templates found in template_kwargs and sets self.kwarg, a version of the current module’s kwargs relate to this events’ content

Parameters:template_kwargs – A dict of the modules kwargs optoinally containing Template instances.
set(value, key='data')[source]

Sets the value of key.

key must be in Scalpl format.

Parameters:
  • value – The value to assign.
  • key – The key to store the value
slurp(data)[source]

Create an event object from a native event dict exported by dump()

The timestamp field will be reset to the time this method has been called.

Parameters:data – The dict object containing the complete event.
Returns:A Wishbone event instance.
Return type:wishbone.event.Event
Raises:InvalidDatadata does not contain valid fields to build an event