activitystream

activitystream.base module

class activitystream.base.ActivityBase

Bases: object

Tells the story of a person performing an action on or with an object.

Consists of an actor, a verb, an object, and optionally a target.

actor None

The actor, or subject, of the Activity.

Example: John posted a comment on ticket #42.

Returns:
NodeBase
obj None

The object of the Activity.

Example: John posted a comment on ticket #42.

Returns:
ObjectBase
published None

The datetime at which the Activity was published.

Returns:
datetime.datetime
target None

The (optional) target of the Activity.

Example: John posted a comment on ticket #42.

Returns:
ObjectBase
verb None

The verb in the Activity.

Example: John posted a comment on ticket #42.

Returns: str

class activitystream.base.ActivityManagerBase

Bases: object

Serializes ActivityBase objects.

create(actor, verb, obj, target=None)

Create and serialize an ActivityBase.

class activitystream.base.ActivityObjectBase

Bases: object

A thing which participates in an Activity.

activity_extras None

A BSON-serializable dict of extra stuff to store on the activity.

activity_name None

Unicode representation of this object.

activity_url None

URL of this object.

class activitystream.base.NodeBase

Bases: object

A node in the network.

node_id None

A string that uniquely identifies this node in the network.

class activitystream.base.NodeManagerBase

Bases: object

Manages the network of connected nodes.

Knows how to connect and disconnect nodes and serialize the graph.

follow(follower, following)

Create a directed edge from NodeBase follower to NodeBase following.

unfollow(follower, following)

Destroy a directed edge from NodeBase follower to NodeBase following.

activitystream.managers module

class activitystream.managers.ActivityManager(activity_coll, node_manager)

Bases: activitystream.base.ActivityManagerBase

Serializes Activity objects.

create(actor, verb, obj, target=None, related_nodes=None)

Create and serialize an Activity.

Serializing includes making a copy of the activity for any node in the network that is connected to any node in the activity.

get_activities(nodes, since=None, sort=None, limit=0, skip=0, query=None)

Return all activities associated with the given nodes.

Params:
since (datetime) - return activities that have occured since this
datetime
get_timeline(node_id, sort=None, limit=0, skip=0, query=None)

Return the timeline for node_id.

Timeline is the already-aggregated list of activities in mongo.

save_activities(activities)

Save (upsert) a list of activities to mongo.

class activitystream.managers.Aggregator(activity_manager, timeline_manager, node_manager)

Bases: object

Creates a timeline for a given node in the network graph.

classify_activities(activities)

Return a list of activities with classfication flags added.

create_timeline(node_id)

Create, store, and return the timeline for a given node.

filter_activities(activities)

Return a subset of a node’s activities using the algorithm of your choice.

filter_connections(nodes)

Return a subset of a node’s total outbound connections (nodes he is following) using the algorithm of your choice.

get_timeline(node, page=0, limit=100, actor_only=False, filter_func=None)

Return a (paged and limited) timeline for node.

page is zero-based (page 0 is the first page of results).

If actor_only == True, timeline will be filtered to only include activities where node is the actor.

Pass a callable to filter_func to arbitrarily filter activities out of the timeline. filter_func will be passed an activity, and should return True to keep the activity in the timeline, or False to filter it out.

Total size of the returned timeline may be less than limit if:
  1. the timeline is exhausted (last page)
  2. activities are filtered out by filter_func
needs_aggregation(node)

Return True if it’s time for this node’s timeline to be (re)aggregated).

score_activities(activities)

Return a scored list of activities. By default, newer activities have higher scores.

truncate_timeline(activities)

Return a truncated timeline using the algorithm of your choice. The timeline activities passed in are already sorted by score, descending.

class activitystream.managers.NodeManager(coll)

Bases: activitystream.base.NodeManagerBase

Manages the network of connected nodes.

Knows how to connect and disconnect nodes and serialize the graph.

follow(follower, following)

Create a directed edge from Node follower to Node following.

get_node(node_id)

Return the node for the given node_id.

get_nodes(node_ids)

Return nodes for the given node_ids.

is_following(follower, following)

Determine if there is a directed edge from Node follower to Node following.

save_node(node)

Save (upsert) a node into the collection.

unfollow(follower, following)

Destroy a directed edge from Node follower to Node following.

Module contents

class activitystream.ActivityDirector(**conf)

Bases: thread._local

connect(follower, following)
create_activity(actor, verb, obj, target=None, related_nodes=None)
create_timeline(node_id)
disconnect(follower, following)
get_timeline(*args, **kw)
is_connected(follower, following)
activitystream.configure(**conf)
activitystream.director()

Table Of Contents

Previous topic

API

Next topic

Changes

This Page