Python Code-Based Transformations

Last updated on Dec 15, 2022

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

Tell us what went wrong