Search documentation...

K
ChangelogBook a demoSign up

Python SDK

The Python SDK makes it easy to track events from Python applications.

Installation

The Python SDK can be installed via pypi.org.

pip install events-sdk-python

To initialize the Python SDK in your application, import htevents and set the write_key:

import hightouch.htevents as htevents

htevents.write_key = 'WRITE_KEY'

API

Identify

The identify method sends an identify event.

Unlike the Browser SDK, it does not persist the user ID and traits locally, so user IDs must be explicitly added to other events. This is because server side events are usually servicing many different users at once.

Example usage:

htevents.identify('user123', {
  'email': 'test@example.com',
  'name': 'John Doe',
})

Method parameters:

ParameterTypeDescription
user_idstrThe user's persistent ID
anonymous_idstrThe user's anonymous ID
traitsdictAdditional traits about the user, such as email and name.
contextdictOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampdatetimeThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Track

The track method sends a track event.

Example usage:

htevents.track('user123', 'Order completed', {
  'product_id': '123',
})

Method parameters:

ParameterTypeDescription
user_idstrThe user's persistent ID
anonymous_idstrThe user's anonymous ID
eventstrThe name of the event.
propertiesdictAdditional properties about the event, such as product_id.
contextdictOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampdatetimeThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Page

The page method sends a page event.

Example usage:

htevents.page('user123', 'Docs', 'Python', {
  'url': 'http://example.com/docs/python'
})

Method parameters:

ParameterTypeDescription
user_idstrThe user's persistent ID
anonymous_idstrThe user's anonymous ID
categorystrThe screen's category. For example "Docs"
namestrThe page's name. For example "Getting started"
propertiesdictAdditional properties about the event, such as url.
contextdictOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampdatetimeThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Screen

The screen method sends a screen event.

Example usage:

htevents.screen('user123', 'Docs', 'Python', {
  'url': 'http://example.com/docs/python'
})

Method parameters:

ParameterTypeDescription
user_idstrThe user's persistent ID
anonymous_idstrThe user's anonymous ID
categorystrThe screen's category. For example "Docs"
namestrThe screen's name. For example "Getting started"
propertiesdictAdditional properties about the event, such as url.
contextdictOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampdatetimeThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Group

The group method sends a group event.

Example usage:

htevents.group('user123', 'group123', {
  'company_name': 'Initech',
})

Method parameters:

ParameterTypeDescription
user_idstrThe user's persistent ID
anonymous_idstrThe user's anonymous ID
group_idstrThe id for the group.
traitsdictAdditional traits about the group, such as company_name.
contextdictOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampdatetimeThe date of the message. When backfilling data, this can be set to a date in the past. By default, this is autoset to the current date.

Flush

The Python SDK buffers events locally before sending them to Hightouch's servers. This minimizes the number of requests made by the SDK and makes the tracking non-blocking.

To force the local buffer to be sent to Hightouch immediately call the flush method. flush should be called when shutting down your Python app to make sure no events are lost.

Example usage:

htevents.flush()

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Last updated: Mar 12, 2024

On this page

InstallationAPIIdentifyTrackPageScreenGroupFlush

Was this page helpful?