skip to navigation
skip to content

gnippy 0.3.6

Python library for GNIP.

Latest Version: 0.6.2

gnippy provides an easy way to access the Power Track stream provided by GNIP. You can also use gnippy to programatically add rules to your Power Track stream.


pip install gnippy


Create a .gnippy file and place it in your home directory. It should contain the following:

username =
password = mypassword

url = https://my.gnip.powertrack/url.json

Fire up the client:

#!/usr/bin/env python
import time
from gnippy import PowerTrackClient

# Define a callback
def callback(activity):
    print activity

# Create the client
client = PowerTrackClient(callback)

# Wait for 2 minutes and then disconnect

If you don’t want to create a config file or you want it put it in another location:

client = PowerTrackClient(callback, config_file_path="/etc/gnippy")
# OR ... provide the url and authentication credentials to override any config files
client = PowerTrackClient(callback, url="http://my.gnip.powertrack/url.json", auth=("uname", "pwd"))

Adding PowerTrack Rules

If you want to add rules to your PowerTrack:

from gnippy import rules
from gnippy.errors import RuleAddFailedException

# Synchronously add rules
    rules.add_rule('(Hello OR World OR "this is a test") AND lang:en', tag="MyRule")
    rules.add_rule('Rule without a tag')
except RuleAddFailedException:
    pass # uh oh

# OR ... synchronously add multiple rules at once
rule_list = []
rule_list.append("Hello World", tag="asdf"))
rule_list.append("Rule Without a Tag"))
except RuleAddFailedException:
    pass # uh oh

# OR ... manually pass in params - overrides any config files
rules.add_rule("My Rule String", tag="mytag", url="http://my.gnip.powertrack/url.json", \
               auth=("uname", "pwd"))

Listing Active PowerTrack Rules

from gnippy import rules
from gnippy.errors import RulesGetFailedException

    rules_list = rules.get_rules()
    # rules_list is in the format:
    # [
    #    { "value": "(Hello OR World) AND lang:en" },
    #    { "value": "Hello", "tag": "mytag" }
    # ]
except RulesGetFailedException:
    pass # uh oh

Deleting PowerTrack Rules

from gnippy import rules
from gnippy.errors import RuleDeleteFailedException, RulesGetFailedException

    rules_list = rules.get_rules()
    # Suppose I want to delete the first rule in the list
    # OR ... I want to delete ALL rules

except RuleDeleteFailedException, RulesGetFailedException:
    pass # uh oh

Source available on GitHub:

File Type Py Version Uploaded on Size
gnippy-0.3.6.tar.gz (md5) Source 2013-08-19 6KB
  • Author: Abhinav Ajgaonkar
  • Home Page:
  • License:
    Copyright 2012-2013 Abhinav Ajgaonkar
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
  • Package Index Owner: abhinav
  • DOAP record: gnippy-0.3.6.xml