quart.sessions module

class quart.sessions.SessionInterface

Bases: object

Base class for session interfaces.

null_session_class

Storage class for null (no storage) sessions.

pickle_based

Indicates if pickling is used for the session.

null_session_class

alias of NullSession

pickle_based = False
async make_null_session(app)

Create a Null session object.

This is used in replacement of an actual session if sessions are not configured or active.

Parameters:

app (Quart)

Return type:

NullSession

is_null_session(instance)

Returns True is the instance is a null session.

Parameters:

instance (object)

Return type:

bool

Helper method to return the Cookie Name for the App.

Parameters:

app (Quart)

Return type:

str

Helper method to return the Cookie Domain for the App.

Parameters:

app (Quart)

Return type:

str | None

Helper method to return the Cookie path for the App.

Parameters:

app (Quart)

Return type:

str

Helper method to return if the Cookie should be HTTPOnly for the App.

Parameters:

app (Quart)

Return type:

bool

Helper method to return if the Cookie should be Secure for the App.

Parameters:

app (Quart)

Return type:

bool

Helper method to return the Cookie Samesite configuration for the App.

Parameters:

app (Quart)

Return type:

str

get_expiration_time(app, session)

Helper method to return the Session expiration time.

If the session is not ‘permanent’ it will expire as and when the browser stops accessing the app.

Parameters:
  • app (Quart)

  • session (SessionMixin)

Return type:

datetime | None

Helper method to return if the Set Cookie header should be present.

This triggers if the session is marked as modified or the app is configured to always refresh the cookie.

Parameters:
  • app (Quart)

  • session (SessionMixin)

Return type:

bool

async open_session(app, request)

Open an existing session from the request or create one.

Returns:

The Session object or None if no session can be created, in which case the null_session_class is expected to be used.

Parameters:
Return type:

SessionMixin | None

async save_session(app, session, response)

Save the session argument to the response.

Parameters:
  • response (Response | WerkzeugResponse | None) – Can be None if the session is being saved after a websocket connection closes.

  • app (Quart)

  • session (SessionMixin)

Returns:

The modified response, with the session stored.

Return type:

None

class quart.sessions.SecureCookieSessionInterface

Bases: SessionInterface

A Session interface that uses cookies as storage.

This will store the data on the cookie in plain text, but with a signature to prevent modification.

static digest_method(string=b'', *, usedforsecurity=True)

Returns a sha1 hash object; optionally initialized with a string

key_derivation = 'hmac'
salt = 'cookie-session'
serializer = <flask.json.tag.TaggedJSONSerializer object>
session_class

alias of SecureCookieSession

get_signing_serializer(app)

Return a serializer for the session that also signs data.

This will return None if the app is not configured for secrets.

Parameters:

app (Quart)

Return type:

URLSafeTimedSerializer | None

async open_session(app, request)

Open a secure cookie based session.

This will return None if a signing serializer is not available, usually if the config SECRET_KEY is not set.

Parameters:
Return type:

SecureCookieSession | None

async save_session(app, session, response)

Saves the session to the response in a secure cookie.

Parameters:
  • app (Quart)

  • session (SessionMixin)

  • response (Response | WerkzeugResponse | None)

Return type:

None