This tutorial shows how the Python SDK can be used to interface with a Squirro project.
Table of Contents
Installation
For installation please follow the Python SDK Installation documentation. If you already have a Python environment set up, then you can install the SquirroClient package with:
pip install SquirroClient
Gathering Information
When working with the Squirro SDK you need to provide a few pieces of information:
- Cluster
- Authentication Token
- Project Identifier
The documentation page Connecting to Squirro explains in detail how this information can be retrieved.
Instantiation & Authentication
As a first step, you need to instantiate the SquirroClient class and then authentication.
In the constructor specify the cluster, for authentication use the user authentication token.
from squirro_client import SquirroClient client = SquirroClient(None, None, cluster='https://next.squirro.net') client.authenticate(refresh_token='570010…fda74e')
Searching Items
Now with a valid connection you can start searching items in an existing Squirro project. Searches are always done in the context of a project, so use the project identifier and get the most recent 15 items in a project with the following code:
print client.query('l0nz…YgBg')
This will output a result like the following (output reformatted and cut to the first two items for clarity):
{u'count': 15, u'eof': False, u'items': [{u'abstract': u'\xa0Twitter is bringing...', u'body': u'<html><body><img wid...', u'created_at': u'2015-03-23T17:03:56', u'external_id': u'http://techcrunch.com/?p=1135621', u'id': u'S8Eh_0a6SEaQwaoYtE85nQ', u'language': u'en', u'link': u'http://techcrunch.com/2015/03/23/twitter-teaming-with-foursquare-for-location-tagging-in-tweets/?ncid=rss', u'modified_at': u'2015-03-23T17:05:26', u'objects': [{u'id': u'vXzfrgmERwy1DAMO_ZBQIw', u'project_id': u'l0nz…YgBg', u'source_ids': [u'8lVtipSSTxu7q-ox1KdCjQ'], u'title': u'default', u'type': u'default'}], u'read': False, u'related_items': [], u'score': 1.0, u'sources': [{u'id': u'8lVtipSSTxu7q-ox1KdCjQ', u'link': u'http://feeds.feedburner.com/TechCrunch', u'object_ids': [u'vXzfrgmERwy1DAMO_ZBQIw'], u'provider': u'feed', u'title': u'TechCrunch'}], u'starred': False, u'thumbler_url': u'd4d…f73/thumb/webshot/52/2d/18/522…5d6.png', u'title': u'Twitter Teaming With Foursquare For Location Tagging In Tweets', u'webshot_height': 2556, u'webshot_url': u'http://webshot.next.squirro.net.s3-website-us-west-1.amazonaws.com/52/2d/18/522…5d6.png', u'webshot_width': 4884}, {u'abstract': u'\xa0Instagram today ann...', u'body': u'<html><body><img wid...', u'created_at': u'2015-03-23T17:00:43', u'external_id': u'http://techcrunch.com/?p=1135559', u'id': u'_Tt7lGnWRMKJ4b-p_zHvow', u'language': u'en', u'link': u'http://techcrunch.com/2015/03/23/instagram-layout/?ncid=rss', u'modified_at': u'2015-03-23T17:01:45', u'objects': [{u'id': u'vXzfrgmERwy1DAMO_ZBQIw', u'project_id': u'l0nz…YgBg', u'source_ids': [u'8lVtipSSTxu7q-ox1KdCjQ'], u'title': u'default', u'type': u'default'}], u'read': False, u'related_items': [], u'score': 1.0, u'sources': [{u'id': u'8lVtipSSTxu7q-ox1KdCjQ', u'link': u'http://feeds.feedburner.com/TechCrunch', u'object_ids': [u'vXzfrgmERwy1DAMO_ZBQIw'], u'provider': u'feed', u'title': u'TechCrunch'}], u'starred': False, u'thumbler_url': u'260…fd9/thumb/webshot/3f/30/a7/3f3…248.jpg', u'title': u'Instagram Launches Layout, Its Own Photo Collage App', u'webshot_height': 1244, u'webshot_url': u'http://webshot.next.squirro.net.s3-website-us-west-1.amazonaws.com/3f/30/a7/3f3…248.jpg', u'webshot_width': 1244}], u'next_params': {u'expected_num_results': 3402, u'start': 15}, u'now': u'2015-03-23T18:01:06', u'total': 3402}
Reference
For a full documentation of the Python SDK refer to the Python SDK Reference, specifically SquirroClient, SquirroClient Entities and SquirroClient Users.