Python Code-Based Transformations

The Transformations UI provides you a Python console where you can modify (transform) the ingested Events to prepare them to be loaded to the Destination. To perform any transformations on your Events, you can change properties of the event object received in the transform method as a parameter. You can add fields, modify or remove them, and even join fields. The environment has all the standard python libraries enabled for you to write your transformations.

def transform(event):
    return event

Hevo runs your transformation code over each Event that is received through the Pipelines.

Refer to API Reference - Event Object for the methods available for you to write the transformations on the event object.

The following is an example of a transformation you create in Hevo:

from ua_parser import user_agent_parser
import datetime

def transform(event):
  event_name = event.getEventName()
  properties = event.getProperties()

  # Concatenate First Name and Last Name of the User to create Full Name
  if event_name == 'users':
    properties['full_name'] = properties['first_name'] + ' ' +  properties['last_name']

  # Parse the User Agent string
  if properties.get('user_agent'):
    user_agent = properties.get('user_agent')
    parsed_string = user_agent_parser.ParseUserAgent(user_agent)
    properties['user_agent'] = parsed_string.get('family')  # Add a timestamp at which the event was streamed
  properties['streamed_ts'] =
  return event

Last updated on 25 Feb 2021