pyramid_redis_sessions.RedisSessionFactory(secret, timeout=1200, cookie_name='session', cookie_max_age=None, cookie_path='/', cookie_domain=None, cookie_secure=False, cookie_httponly=True, cookie_on_exception=True, url=None, host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None, client_callable=None, serialize=<built-in function dumps>, deserialize=<built-in function loads>, id_generator=<function _generate_session_id>)[source]

Constructs and returns a session factory that will provide session data from a Redis server. The returned factory can be supplied as the session_factory argument of a pyramid.config.Configurator constructor, or used as the session_factory argument of the pyramid.config.Configurator.set_session_factory() method.


secret A string which is used to sign the cookie.

timeout A number of seconds of inactivity before a session times out.

cookie_name The name of the cookie used for sessioning. Default: session.

cookie_max_age The maximum age of the cookie used for sessioning (in seconds). Default: None (browser scope).

cookie_path The path used for the session cookie. Default: /.

cookie_domain The domain used for the session cookie. Default: None (no domain).

cookie_secure The ‘secure’ flag of the session cookie. Default: False.

cookie_httponly The ‘httpOnly’ flag of the session cookie. Default: True.

cookie_on_exception If True, set a session cookie even if an exception occurs while rendering a view. Default: True.

url A connection string for a Redis server, in the format: redis://username:password@localhost:6379/0 Default: None.

host A string representing the IP of your Redis server. Default: localhost.

port An integer representing the port of your Redis server. Default: 6379.

db An integer to select a specific database on your Redis server. Default: 0

password A string password to connect to your Redis server/database if required. Default: None.

client_callable A python callable that accepts a Pyramid request and Redis config options and returns a Redis client such as redis-py’s StrictRedis. Default: None.

serialize A function to serialize the session dict for storage in Redis. Default: cPickle.dumps.

deserialize A function to deserialize the stored session data in Redis. Default: cPickle.loads.

id_generator A function to create a unique ID to be used as the session key when a session is first created. Default: private function that uses sha1 with the time and random elements to create a 40 character unique ID.

The following arguments are also passed straight to the StrictRedis constructor and allow you to further configure the Redis client:


This function is detected by Pyramid so that you can easily include pyramid_redis_sessions in your main method like so:



config A Pyramid config.Configurator


Convenience method to construct a RedisSessionFactory from Paste config settings. Only settings prefixed with “redis.sessions” will be inspected and, if needed, coerced to their appropriate types (for example, casting the timeout value as an int).


settings A dict of Pyramid application settings

RedisSession.adjust_timeout_for_session(session, *arg, **kw)