file_backend#

class starlite.middleware.session.file_backend.FileStorageMetadataWrapper#

Bases: NamedTuple

Metadata of a session file.

expires: str#

Alias for field number 0

data: str#

Alias for field number 1

static __new__(_cls, expires: str, data: str)#

Create new instance of FileStorageMetadataWrapper(expires, data)

class starlite.middleware.session.file_backend.FileBackend#

Bases: ServerSideBackend[FileBackendConfig]

Session backend to store data in files.

__init__(config: FileBackendConfig) None#

Initialize FileBackend

Parameters:

config – A FileBackendConfig

async get(session_id: str) Optional[bytes]#

Load data associated with session_id from a file.

Parameters:

session_id – The session-ID

Returns:

The session data, if existing, otherwise None.

async set(session_id: str, data: bytes) None#

Store data alongside metadata under the session_id, using the ID as a filename. If a file already exists for session_id, replace it with data and reset its expiry time.

Parameters:
  • session_id – The session-ID

  • data – Serialized session data

Returns:

None

async delete(session_id: str) None#

Delete the file associated with session_id.

Fails silently if no such file exists

Parameters:

session_id – The session-ID

Returns:

None

async delete_all() None#

Delete all files in the storage path.

Returns:

None

async delete_expired() None#

Delete expired session files.

Returns:

None

class starlite.middleware.session.file_backend.FileBackendConfig#

Bases: ServerSideSessionConfig

Backend configuration for FileBackend

storage_path: PathLike#

Disk path under which to store session files.

make_filename: Optional[Callable[[str], str]]#

Callable that turns a session-ID into a filename used for storage.

By default, the session-ID will be used as a filename