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.
-
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.
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 givenhostname
,port
anddb
- the
get_connection
can be used safely at any time afterconnection_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 tolocalhost
port
- an integer with the port to connect to, defaults to6379
db
- a positive integer with the redis db to connect to, defaults to0
- the
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.
-
classmethod