mixpanel/mixpanel-python — pull request #20 by cooncesean (2014-08-01 17:59:18+00:00)
Title: Import Data Functionality

**Summary Of Changes:**
This PR adds functionality to allow the import of "historical" data extending more than 5 days in the past. The new `Mixpanel.import_data()` method takes advantage of [MixPanel's `/import/` endpoint which is outlined here](https://mixpanel.com/docs/api-documentation/importing-events-older-than-31-days).

Unit tests have been added to cover these changes.

**Implementation Notes:**
Notably, the new `import_data()` method acts in a similar fashion to `track()` (boilerplate logic could eventually be abstracted) but takes two required args: `api_key` and `timestamp` which are documented in the method's docstring.

The `Consumer` class has been updated to handle the new endpoint as well as stuff an optional `api_key` arg (specified in the `import_data` method) onto the request.

**Usage:**
Here is how the new method would be invoked using the Django ORM.

```python
import datetime

from my_app.conf import YOUR_MIXPANEL_TOKEN, YOUR_MIXPANEL_API_KEY
from my_app.models import SomeEvent

# Instantiate an mixpanel instance as you normally would
mp = MixPanel(YOUR_TOKEN)

# Fetch an 'old' event from the db that we want to add to MixPanel
old_event = SomeEvent.objects.get(create_date__lt=datetime.datetime.now() - datetime.timedelta.days(6))
mp.import_data(
YOUR_MIXPANEL_API_KEY, # Requests requires your API key as an extra layer of security
old_event.id,
'Some Event',
old_event.timestamp, # Request requires an explicit timestamp
{
... your custom properties and meta ...
}
)
```