AwesomeStream

Makes awesome streams
Download

AwesomeStream Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Eric Florenzano
  • Publisher web site:
  • http://code.google.com/u/floguy/

AwesomeStream Tags


AwesomeStream Description

Makes awesome streams The AwesomeStream project offers a set of tools for creating a "stream server". That is, a server which can store information about events that happen, and can query back those events in reverse-chronological order, sliced in interesting ways.Example and Use CaseSay that you run a website like GitHub, where people interact in various different ways. People can create repositories, fork them, watch or unwatch repositories, add friends, etc. There are all kinds of things that a user can do on the site. Let's look at how AwesomeStream can help.First, we'll set up a simple redis-based server: >>> from awesomestream.backends import RedisBackend >>> from awesomestream.jsonrpc import create_app, run_server >>> backend = RedisBackend( ... keys=, ... host='127.0.0.1', ... port=6379 ... ) >>> >>> app = create_app(backend) >>> run_server(app, 8080)This simple script sets up a Redis-based AwesomeStream server--one that pays special attention to the 'user', 'kind', and 'repo' keys. This will make a bit more sense in a bit.In another console, we're going to instantiate a client. >>> from awesomestream.jsonrpc import Client >>> c = Client('http://127.0.0.1:8080/')OK, now that we've set up our client, lets start logging user actions. Look, a user has just created a new repo! >>> c.insert({ ... 'kind': 'create-repo', ... 'repo': 17, ... 'user': 291, ... 'name': 'frist', ... 'description': 'This is my first repo ever!', ... }) >>>But the user made a mistake, and named it 'frist' instead of 'first'. So they go ahead and delete it: >>> c.insert({ ... 'kind': 'delete-repo', ... 'repo': 17, ... 'user': 291, ... 'reason': 'Made a typo :(', ... }) >>>Then they give up and decide to watch another user's repo instead: >>> c.insert({'kind': 'watch', 'repo': 2842, 'user': 291, 'owner': 23})And finally they add that user as a friend: >>> c.insert({'kind': 'friend', 'user': 291, 'friend': 23})That second user notices that someone is following them, and follows back: >>> c.insert({'kind': 'friend', 'user': 23, 'friend': 291})Now that we have data inserted into the stream server, we can query it to get back the full stream. Here's how something like that might look: >>> c.items() As you can see, we got the entire stream back, in reverse chronological order. But let's say we want to filter this out, to only see 'friend' requests. We can do that easily: >>> c.items(kind='friend') Notice that they are still in reverse chronological order. We can also combine our predicates, to get only friend requests made by a specific user. >>> c.items(kind='friend', user=23) But an extremely common case is that you want to see only your activity that is generated by your friends. With AwesomeStream, that's simple: >>> c.items(user=) As you can see, every user ID passed into that list is retrieved. By default, the items() function retrieves 20 items, but often times we'll need to customize that. Here's how that would look: >>> c.items(user=, start=1, end=3) Supported Backends * In-Memory (mostly for testing) * SQL * RedisRequirementsShort Summary: Use pip, and do pip install -U -r requirements.txtLonger Summary: Strictly speaking, the only requirement is simplejson. That being said, if you want redis support, you need redis installed. If you want SQL support, you need SQLAlchemy installed. If you want support for creating a WSGI app to expose this over HTTP, you'll need werkzeug installed. Finally, if you want a simple, pure-python way of running that WSGI app, you'll want to install cherrypy. Requirements: · Python


AwesomeStream Related Software