SaltyCrane Blog — Notes on JavaScript and web development

How to use gnip-python to retrieve activity from Twitter, Delicious, Digg, etc.

  • Create an account at
  • Download gnip-python from
  • Unpack it:
    $ tar -zxvf gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e.tar.gz
  • Move it to your example directory:
    $ mkdir ~/src/python/gnip-example
    $ mv gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e/*.py ~/src/python/gnip-example
  • Create an example file called ~/src/python/gnip-example/
    #!/usr/bin/env python
    from gnip import *
    gnip = Gnip("[email protected]", "yourpassword")
    for publisher in ["twitter", "digg", "delicious"]:
        activities = gnip.get_publisher_activities(publisher)
        print publisher
        for activity in activities[:5]:
            print activity
  • Run it:
    $ python

    And get the following results:
    [derricklo, 2008-08-01T22:49:59+00:00, tweet,]
    [sam_metal, 2008-08-01T22:50:01+00:00, tweet,]
    [lalatina, 2008-08-01T22:49:59+00:00, tweet,]
    [Nochipra, 2008-08-01T22:50:01+00:00, tweet,]
    [jmcgaha, 2008-08-01T22:50:01+00:00, tweet,]
    [DAlexopoulos, 2008-08-01T18:50:08+00:00, submission,]
    [EradicateIV, 2008-08-01T18:50:05+00:00, submission,]
    [vivianpetman, 2008-08-01T18:49:58+00:00, submission,]
    [portia7896, 2008-08-01T18:49:53+00:00, submission,]
    [hhdepot, 2008-08-01T18:49:52+00:00, submission,]
    [hanasama1, 2008-08-01T22:49:55+00:00, delicious,]
    [Chrmftcotl, 2008-08-01T22:49:54+00:00, delicious,]
    [shankar, 2008-08-01T22:49:53+00:00, delicious,]
    [grzyweasel, 2008-08-01T22:49:53+00:00, delicious,]
    [metaffect, 2008-08-01T22:50:05+00:00, delicious,]
    Pretty cool.

This is just scratching the surface of what you can do with gnip. You can also filter by time or user. Or get XML output. Or you can publish to gnip yourself. See the gnip-python README for more python examples or the Gnip API for more detailed information. Also, here is a list of Gnip publishers.

If you get a ImportError: No module named iso8601 error, install iso8601.