Stream Framework allows you to build newsfeed and notification systems
using Cassandra and/or Redis. Examples of what you can build are the
Facebook newsfeed, your Twitter stream or your Pinterest following page.
We’ve built Feedly for Fashiolista
where it powers the flat
feed, aggregated
feed and the
notification
system. (Feeds
are also commonly called: Activity Streams, activity feeds, news
streams.)

To quickly make you acquainted with Stream Framework, we’ve created a
Pinterest like example application, you can find it
here

Stream Framework’s authors also offer a Saas solution for building feed
systems at getstream.io The hosted service is
highly optimized and allows you start building your application
immediatly. It saves you the hastle of maintaining Cassandra, Redis,
Faye, RabbitMQ and Celery workers. Clients are available for
Node,
Ruby,
Python,
Java and
PHP

Next up we want to start publishing this activity on several feeds.
First of we want to insert it into your personal feed, and secondly into
the feeds of all your followers. Lets start first by defining these
feeds.

# setting up the feedsfromstream_framework.feeds.redisimportRedisFeedclassPinFeed(RedisFeed):key_format='feed:normal:%(user_id)s'classUserPinFeed(PinFeed):key_format='feed:user:%(user_id)s'

Writing to these feeds is very simple. For instance to write to the feed
of user 13 one would do

feed=UserPinFeed(13)feed.add(activity)

But we don’t want to publish to just one users feed. We want to publish
to the feeds of all users which follow you. This action is called a
fanout and is abstracted away in the manager class. We need to subclass
the Manager class and tell it how we can figure out which user follow
us.

fromstream_framework.feed_managers.baseimportManagerclassPinManager(Manager):feed_classes=dict(normal=PinFeed,)user_feed_class=UserPinFeeddefadd_pin(self,pin):activity=pin.create_activity()# add user activity adds it to the user feed, and starts the fanoutself.add_user_activity(pin.user_id,activity)defget_user_follower_ids(self,user_id):ids=Follow.objects.filter(target=user_id).values_list('user_id',flat=True)return{FanoutPriority.HIGH:ids}manager=PinManager()

Now that the manager class is setup broadcasting a pin becomes as easy
as

manager.add_pin(pin)

Calling this method wil insert the pin into your personal feed and into
all the feeds of users which follow you. It does so by spawning many
small tasks via Celery. In Django (or any other framework) you can now
show the users feed.

# django example@login_requireddeffeed(request):''' Items pinned by the people you follow '''context=RequestContext(request)feed=manager.get_feeds(request.user.id)['normal']activities=list(feed[:25])context['activities']=activitiesresponse=render_to_response('core/feed.html',context)returnresponse

This example only briefly covered how Stream Framework works. The full
explanation can be found on read the docs.