class watson.http.sessions.abc.StorageMixin(id=None, timeout=None, autosave=True)[source]

The base mixin for all session storage adapters.

By default, if no id is specified when the session is created a new session id will be generated. When a user is logged in, it is good practice to regenerate the id of the session id to prevent session hijacking.

If autosave is set to True, then when data is added to the session the save() method will be called. If set to False, the developer will be required to manually call the save() method themselves.

To function correctly sessions require that cookies are enabled in the users browser.


session = SessionStorageMethod()
# where SessionStorageMethod is a valid storage class
session['key'] = 'some value'
session['key'] # 'some value'
__init__(id=None, timeout=None, autosave=True)[source]
  • id – the id of the session
  • timeout – the expiry time from the current time in seconds
  • key – the key used to reference the session id in a cookie
  • autosave – save the contents on __setitem__

The cookie params used when saving the session id as a cookie.


The data associated with the session.


Destroy the session data from storage, but leave the actual session intact.


Determine whether or not the session exists in storage.

Returns:Boolean whether or not the session id exists.
Returns:A new session id based on a random 24 char string

The id of the session.


Loads the data from storage into the session. If the session data was set to expire before the current time, destroy the session.


Regenerate a new id for the session.


Save the contents of the session into storage.

watson.http.sessions.abc.random() → x in the interval [0, 1).