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:
| Parameter | Type | Description |
|---|---|---|
user_id | str | The user's persistent ID |
anonymous_id | str | The user's anonymous ID |
traits | dict | Additional traits about the user, such as email and name. |
context | dict | Overrides to values in the event context. By default, context contains information autocollected by the SDK. |
timestamp | datetime | The 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:
| Parameter | Type | Description |
|---|---|---|
user_id | str | The user's persistent ID |
anonymous_id | str | The user's anonymous ID |
event | str | The name of the event. |
properties | dict | Additional properties about the event, such as product_id. |
context | dict | Overrides to values in the event context. By default, context contains information autocollected by the SDK. |
timestamp | datetime | The 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:
| Parameter | Type | Description |
|---|---|---|
user_id | str | The user's persistent ID |
anonymous_id | str | The user's anonymous ID |
category | str | The screen's category. For example "Docs" |
name | str | The page's name. For example "Getting started" |
properties | dict | Additional properties about the event, such as url. |
context | dict | Overrides to values in the event context. By default, context contains information autocollected by the SDK. |
timestamp | datetime | The 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:
| Parameter | Type | Description |
|---|---|---|
user_id | str | The user's persistent ID |
anonymous_id | str | The user's anonymous ID |
category | str | The screen's category. For example "Docs" |
name | str | The screen's name. For example "Getting started" |
properties | dict | Additional properties about the event, such as url. |
context | dict | Overrides to values in the event context. By default, context contains information autocollected by the SDK. |
timestamp | datetime | The 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:
| Parameter | Type | Description |
|---|---|---|
user_id | str | The user's persistent ID |
anonymous_id | str | The user's anonymous ID |
group_id | str | The id for the group. |
traits | dict | Additional traits about the group, such as company_name. |
context | dict | Overrides to values in the event context. By default, context contains information autocollected by the SDK. |
timestamp | datetime | The 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()