1.2.2 Drivers

The web.auth module is designed so that the data can be stored in lots of different ways through the use of different drivers. Currently only a database storage driver exists which allows session information to be stored in any relational database supported by the web.database module. The web.database module includes SnakeSQL, a pure Python database which works like a library, so you can use the web.session module even if you do not have access to another relational database engine.

To use the AuthSession and AuthManager objects we need to obtain a valid Driver object. This is done as follows:

import web, web.database, web.auth

connection = web.database.connect('mysql', database='test')
cursor = connection.cursor()

driver = web.auth.driver('database', environment='testEnv', cursor=cursor)

In this example we are using a database to store the session information so we setup a database cursor named cursor as described in the documentation for the web.database module and use it to pass to the web.session.driver() method.

The environment parameter is the name of the environment to be used (see the next section for information on environments).