This Python library wraps the Emotient Analytics API. For more information on the Emotient Analytics API and the Python code examples, see the Emotient Analytics API documentation.
The Emotient Python SDK is hosted at GitHub and is free to use. We accept bug fixes and other enhancements through GitHub pull requests.
You don't need this source code unless you want to modify the library.
To install the library, run:
pip install emotient
To install from source, run:
git clone https://github.com/emotient/emotient-python.git
cd emotient-python
python setup.py install
To use the Emotient Python SDK, you need an API key. If you don't have an Emotient Analytics account, create one, and go to Emotient Analytics API Access to get your key.
The following example shows how to use your API key with the Emotient Python SDK:
from emotient import EmotientAnalyticsAPI
api_key = "91se93z0-f73f-498a-b744-8d1e3a061fcf"
client = EmotientAnalyticsAPI(api_key)
Group objects have similar functionality as media. You can create, retrieve, update, delete, and download aggregated analytics for groups.
-
Retrieve all media:
all_media = client.media.all()
-
Retrieve a list of media:
media_list = client.media.list(page=1, per_page=500) for media in media_list: print(media.id)
-
Retrieve a media object by ID, print the filename, and update the metadata:
media_id = 'c2128139-a984-b695-52a4-eae8021103bb' media = client.media.retrieve(media_id) print(media.data['filename']) media.update(meta_data={'tag': 'long video'})
-
Delete a media object (this is irreversible):
media_id = 'c2128139-a984-b695-52a4-eae8021103bb' media = client.media.retrieve(media_id) media.delete()
-
Upload a new video, create a group, and add the new media to the group:
video_path = 'your/user/path/clip.mp4' with open(video_path, 'rb') as fp: new_media = client.media.upload(fp) new_group = client.groups.create(name='My Group') new_group.media.add(new_media)
-
Download the Emotient Analytics CSV files for a media object:
media_id = 'c2128139-a984-b695-52a4-eae8021103bb' media = client.media.retrieve(media_id) analytics_file = 'your/user/path/analytics.csv' with open(analytics_file, 'w') as fp: media.analytics(fp) aggregated_analytics_file = 'your/user/path/aggregated_analytics.csv' with open(aggregated_analytics_file, 'w') as fp: media.aggregated_analytics(fp, interval='summary', report='standard', gender='combined'`
-
List media in a group:
group_id = 'c2128139-a984-b695-52a4-eae8021103bb' group = client.groups.retrieve(group_id) group_media_list = group.media.list(page=1, per_page=500) for media in group_media_list: print(media.id)
- Fork it and clone
- Create your script branch with
git checkout -b my-edit
- Commit your changes with
git commit -am 'Add some edit'
- Push to the branch with
git push origin my-edit
- Create a new Pull Request
For more information, send us an email at [email protected].