Stream Framework API Docs

activity Module

class stream_framework.activity.Activity(actor, verb, object, target=None, time=None, extra_context=None)[source]

Bases: stream_framework.activity.BaseActivity

Wrapper class for storing activities Note

actor_id target_id and object_id are always present

actor, target and object are lazy by default

get_dehydrated()[source]

returns the dehydrated version of the current activity

serialization_id

serialization_id is used to keep items locally sorted and unique (eg. used redis sorted sets’ score or cassandra column names)

serialization_id is also used to select random activities from the feed (eg. remove activities from feeds must be fast operation) for this reason the serialization_id should be unique and not change over time

eg: activity.serialization_id = 1373266755000000000042008 1373266755000 activity creation time as epoch with millisecond resolution 0000000000042 activity left padded object_id (10 digits) 008 left padded activity verb id (3 digits)

Returns:int –the serialization id
class stream_framework.activity.AggregatedActivity(group, activities=None, created_at=None, updated_at=None)[source]

Bases: stream_framework.activity.BaseActivity

Object to store aggregated activities

activity_count

Returns the number of activities

activity_ids

Returns a list of activity ids

actor_count

Returns a count of the number of actors When dealing with large lists only approximate the number of actors

actor_ids
append(activity)[source]
contains(activity)[source]

Checks if activity is present in this aggregated

get_dehydrated()[source]

returns the dehydrated version of the current activity

get_hydrated(activities)[source]

expects activities to be a dict like this {‘activity_id’: Activity}

is_read()[source]

Returns if the activity should be considered as seen at this moment

is_seen()[source]

Returns if the activity should be considered as seen at this moment

last_activities
last_activity
max_aggregated_activities_length = 15
object_ids
other_actor_count
remove(activity)[source]
remove_many(activities)[source]
serialization_id

serialization_id is used to keep items locally sorted and unique (eg. used redis sorted sets’ score or cassandra column names)

serialization_id is also used to select random activities from the feed (eg. remove activities from feeds must be fast operation) for this reason the serialization_id should be unique and not change over time

eg: activity.serialization_id = 1373266755000000000042008 1373266755000 activity creation time as epoch with millisecond resolution 0000000000042 activity left padded object_id (10 digits) 008 left padded activity verb id (3 digits)

Returns:int –the serialization id
update_read_at()[source]

A hook method that updates the read_at to current date

update_seen_at()[source]

A hook method that updates the seen_at to current date

verb
verbs
class stream_framework.activity.BaseActivity[source]

Bases: object

Common parent class for Activity and Aggregated Activity Check for this if you want to see if something is an activity

class stream_framework.activity.DehydratedActivity(serialization_id)[source]

Bases: stream_framework.activity.BaseActivity

The dehydrated verions of an Activity. the only data stored is serialization_id of the original

Serializers can store this instead of the full activity Feed classes

get_hydrated(activities)[source]

returns the full hydrated Activity from activities

Parameters:a dict {'activity_id' (activities) – Activity}
class stream_framework.activity.NotificationActivity(*args, **kwargs)[source]

Bases: stream_framework.activity.AggregatedActivity

default_settings Module

exceptions Module

exception stream_framework.exceptions.ActivityNotFound[source]

Bases: exceptions.Exception

Raised when the activity is not present in the aggregated Activity

exception stream_framework.exceptions.DuplicateActivityException[source]

Bases: exceptions.Exception

Raised when someone sticks a duplicate activity in the aggregated activity

exception stream_framework.exceptions.SerializationException[source]

Bases: exceptions.Exception

Raised when encountering invalid data for serialization

settings Module

stream_framework.settings.import_global_module(module, current_locals, current_globals, exceptions=None)[source]

Import the requested module into the global scope Warning! This will import your module into the global scope

Example:
from django.conf import settings import_global_module(settings, locals(), globals())
Parameters:
  • module – the module which to import into global scope
  • current_locals – the local globals
  • current_globals – the current globals
  • exceptions – the exceptions which to ignore while importing

tasks Module

utils Module

class stream_framework.utils.LRUCache(capacity)[source]
get(key)[source]
set(key, value)[source]
stream_framework.utils.chunks(iterable, n=10000)[source]
stream_framework.utils.datetime_to_epoch(dt)[source]

Convert datetime object to epoch with millisecond accuracy

stream_framework.utils.epoch_to_datetime(time_)[source]
stream_framework.utils.get_class_from_string(path, default=None)[source]

Return the class specified by the string.

stream_framework.utils.get_metrics_instance()[source]

Returns an instance of the metric class as defined in stream_framework settings.

stream_framework.utils.make_list_unique(sequence, marker_function=None)[source]

Makes items in a list unique Performance based on this blog post: http://www.peterbe.com/plog/uniqifiers-benchmark

class stream_framework.utils.memoized(func)[source]

Bases: object

Decorator. Caches a function’s return value each time it is called. If called later with the same arguments, the cached value is returned (not reevaluated).

stream_framework.utils.warn_on_duplicate(f)[source]
stream_framework.utils.warn_on_error(f, exceptions)[source]