API Reference

Attributes

class repocket.attributes.Attribute(null=False, default=None, encoding=u'utf-8')[source]

Repocket treats its models and attributes as fully serializable. Every attribute contains a to_python method that knows how to serialize the type safely.

classmethod cast(value)[source]

Casts the attribute value as the defined __base_type__.

classmethod get_base_type()[source]

Returns the __base_type__

to_python(value, simple=False)[source]

Returns a json-safe, serialiazed version of the attribute

to_string(value)[source]

Utility method that knows how to safely convert the value into a string

class repocket.attributes.AutoUUID(null=False, default=None, encoding=u'utf-8')[source]

Automatically assigns a uuid1 as the value. __base_type__ = uuid.UUID

class repocket.attributes.ByteStream(null=False, default=None, encoding=u'utf-8')[source]

Handles bytes that will be stored as a string in redis __base_type__ = bytes

class repocket.attributes.Bytes(null=False, default=None, encoding=u'utf-8')[source]

Handles raw byte strings __base_type__ = bytes

class repocket.attributes.DateTime(auto_now=False, null=False)[source]

Repocket treats its models and attributes as fully serializable. Every attribute contains a to_python method that knows how to serialize the type safely.

class repocket.attributes.Decimal(null=False, default=None, encoding=u'utf-8')[source]

Handles Decimal __base_type__ = Decimal

class repocket.attributes.Float(null=False, default=None, encoding=u'utf-8')[source]

Handles float __base_type__ = float

class repocket.attributes.Integer(null=False, default=None, encoding=u'utf-8')[source]

Handles int __base_type__ = int

class repocket.attributes.JSON(null=False, default=None, encoding=u'utf-8')[source]

This special attribute automatically stores python data as JSON string inside of redis. ANd automatically deserializes it when retrieving. __base_type__ = unicode

class repocket.attributes.Pointer(to_model, null=False)[source]

Think of it as a soft foreign key.

This will automatically store the unique id of the target model and automatically retrieves it for you.

classmethod cast(value)[source]

this method uses a redis connection to retrieve the referenced item

class repocket.attributes.UUID(null=False, default=None, encoding=u'utf-8')[source]

Automatically assigns a uuid1 as the value. __base_type__ = uuid.UUID

class repocket.attributes.Unicode(null=False, default=None, encoding=u'utf-8')[source]

Handles unicode-safe values __base_type__ = unicode

Redis connections

class repocket.connections.configure[source]

global redis connection manager. this class is intended to be used as a singleton:

  • the connection_pool method will set a global connection pool with the given hostname, port and db
  • the get_connection can be used safely at any time after connection_pool was already set.
classmethod connection_pool(hostname='localhost', port=6379, db=0)[source]

sets the global redis connection pool.

arguments

  • hostname - a string pointing to a valid hostname, defaults to localhost
  • port - an integer with the port to connect to, defaults to 6379
  • db - a positive integer with the redis db to connect to, defaults to 0
classmethod get_connection()[source]

returns a connection from the pool. this method should only be called after you already called connection_pool

Models

class repocket.model.ActiveRecord(*args, **kw)[source]

base model class, this is how you declare your active record.

class User(ActiveRecord):
    id = attributes.AutoUUID()
    github_access_token = attributes.Bytes()
    name = attributes.Unicode()
    email = attributes.Unicode()
    carpentry_token = attributes.Bytes()
    github_metadata = attributes.JSON()

obj1 = User(
    github_access_token=b'sometoken',
    email='foo@bar.com',
    carpentry_token=b'1234',
    github_metadata={
        'yay': 'this is json baby!'
    }
)

key = obj1.save()
connection = configure.get_connection()
raw_results = connection.hgetall(key)
classmethod create(**kwargs)[source]

Takes all the valid attributes of an active record, saves it immediately and returns the instance, ready for further manipulation.

delete()[source]

Deletes all the redis keys used by this model

matches(kw)[source]

Takes a dictionary with keyword args and returns true if all the args match the model field values

save()[source]

Persists the model in redis. Automatically generates a primary key value if one was not provided

Exceptions

exception repocket.errors.RepocketActiveRecordDefinitionError[source]

Exception raised when a model has more than one AutoUUID or any other kind of inconsistency in the model declaration.