Tealium for Python

Tealium for Python

by on ‎04-15-2016 11:12 AM - edited on ‎09-27-2017 09:21 AM by adapowers (1,951 Views)

This guide shows how to add Tealium to your Python application to track activity in the Universal Data Hub.

Table of Contents Placeholder

Getting Started



The Tealium for Python package can be installed using pip. If you haven't used pip before please read the pip installation guide.

Using Python 2:

pip install tealium

Using Python 3:

pip3 install tealium


Once the Tealium for Python package is installed you are ready to start coding. Use the following code to import the Tealium module and initialize with the following parameters:

  • account - the name of your account
  • profile - the name of the profile within your account
  • environment - (optional) one of "qa", or "prod"
  • path - (optional) path to save persisted data
  • datasource - (optional) the data source key from UDH

It may be necessary to use named parameters when omitting optional parameters from the call, e.g. "datasource" must be named if omitting "path".

from tealium import Tealium
teal = Tealium('account', 'profile', 'environment', datasource:'datasource')


Once the Tealium object has been defined you can begin tracking events with the method trackEvent(), which takes the following parameters:

  • event (required) - a name to identify the event
  • data - optional dictionary with event data as key/value pairs
  • callback - optional callback function

A function that triggers or responds to an event trigger could look like the following:  

def tealiumCallback(info, success, error=None):
if error is not None:
print (info, success, error)
print (info, success)

eventData = {'someKey': 'someValue'}

Additional Resources

Function Definitions


Creates a Tealium object that will be used to track events.

Tealium(account, profile, environment, path, datasource)
Parameters Type Description
account String Tealium account name eg. "companyXYZ"
profile String Tealium profile name eg. "main"
environment (optional) String Tealium environment identifer eg. "prod"
path (optional) String Where to save persistent data eg. "/path/to/persist/data"
datasource (optional) String The data source key from UDH eg. "abc123"


Creates a Tealium object that will be used to track events.

trackEvent(eventName, data, callback)
Parameters Type Description
eventName String Name of the event eg. "user_login"
data Dictionary Dictionary of additional data source keys and values (optional)
callback Function Optional callback function


Reset the session ID. For use when needing to start a new session other than at app start time.

Returns Description Example Value
String A timestamp in milliseconds, converted to a String, that is associated with all subsequent tracking. The session ID is maintained internally and automatically included as the tealium_vid event attribute. "1473371215123"