We are happy to announce the release of version 0.5.0 of the Snowplow Python Tracker! This release is focused mainly on synchronizing the Python Tracker’s support for POST requests with the rest of Snowplow, but also makes its API more consistent.
In this post we will cover:
- POST requests
- New feature: multiple emitters
- More consistent API for callbacks
- More consistent API for tracker methods
- Bug fix: flushing an empty buffer
The POST requests sent by the Python Tracker have been changed in three ways:
- All numerical fields (such as event timestamp) are now converted to strings, so that they can be handled by the same logic that handles fields in GET requests
- Instead of being sent to mycollector.cloudfront.com/i, POST requests are now sent to mycollector.cloudfront.com/com.snowplowanalytics.snowplow/tp2 to flag that they use a slightly different tracker protocol from GET requests
- The content-type for POSTs is now set to “application/json; charset=utf-8”
It is now possible to create a tracker instance which sends events to multiple emitters by supplying an array of emitters to the tracker constructor:
After constructing the tracker, you can add more emitters:
All events created by the tracker will be sent all three emitters.
In version 0.4.0, the Emitter class was introduced. Emitters could be given two callbacks:
on_failure. Whenever the Emitter’s buffer of events was flushed and a request returned with status code not equal to 200, the on_failure callback would be called with two arguments: the number of requests that succeeded, and an object containing the event data for the requests that failed.
The second argument was handled inconsistently. In the case of GET requests, it was an array of dictionaries, each dictionary containing the name-value pairs for an event. In the case of POST requests, it was a stringified JSON.
This release changes the second argument given to the callback in the POST request case to be of the same form as for the GET request case. This means that the same
on_failure callback function will work with both types of request.
In version 0.4.0, the value returned by the tracker methods was variable. If the method caused a synchronous request to be sent, the status code of that request was returned. Otherwise, the tracker instance was returned, allowing chained method calls like:
This version eliminates the former behavior. All tracker methods now return
self, and so can be safely chained.
Previous versions of the Tracker sent a random 6-digit transaction ID used by Snowplow to prevent duplication of events. These were not sufficiently unique, so we have replaced them with version 4 UUIDs, which becomes the enriched event’s
event_id (instead of generating a new
event_id in the Snowplow Enrich process).
Version 0.4.0 had a bug where flushing an emitter configured to send POST requests when its buffer was empty caused it to send POST request with no events in. This behavior has been eliminated.
The release version of this tracker (0.5.0) is available on PyPI, the Python Package Index repository, as snowplow-tracker. Download and install it with pip:
Or with setuptools:
For more information on getting started with the Snowplow Python Tracker, see the setup page.