Installation#

Install from PyPI using an installer such as pip:

$ pip install Flask-Session

Flask-Session’s only required dependency is msgspec for serialization, which has no sub-dependencies.

However, you also need to choose a storage type and install an appropriate client library so the app can communicate with storage. For example, if you want to use Redis as your storage, you will need to install the redis-py library either directly or as an optional dependency like below:

$ pip install Flask-Session[redis]

Redis is the recommended storage type for Flask-Session, as it has the most complete support for the features of Flask-Session with minimal configuration.

Warning

Flask-Session versions below 1.0.0 (not yet released), use pickle as the default serializer, which may have security implications in production if your storage is ever compromised.

Available storage options#

To install Flask-Session with support for a specific storage backend, use the following command, replacing <storage-option> with your chosen backend from the list below:

pip install Flask-Session[<storage-option>]

Available storage options and their corresponding <storage-option> values are:

Storage

<storage-option>

Default client library

Alternative client libraries

Redis

redis

redis-py

Memcached

memcached

pymemcache

pylibmc, python-memcached, libmc

MongoDB

mongodb

pymongo

CacheLib

cachelib

cachelib

SQLAlchemy

sqlalchemy

flask-sqlalchemy

DynamoDB

dynamodb

boto3

Other storage backends might be compatible with Flask-Session as long as they adhere to the command interfaces used by the libraries listed above.

Cachelib#

Flask-Session also indirectly supports storage and client libraries via cachelib, which is a wrapper around various cache libraries. You must also install cachelib itselfand the relevant client library to use these.

Storage

Client Library

File System

Not required

Simple Memory

Not required

UWSGI

uwsgi

Redis

redis-py

Memcached

pylibmc, python-memcached, libmc or google.appengine.api.memcached

MongoDB

pymongo

DynamoDB

boto3

Warning

As of writing, cachelib still uses pickle as the default serializer, which may have security implications in production if your storage is ever compromised.