"""icon" sizes="16x16" href="_static/icon/favicon-16x16.png" type="image/png"> """icon" sizes="32x32" href="_static/icon/favicon-32x32.png" type="image/png"> """icon" sizes="48x48" href="_static/icon/favicon-48x48.png" type="image/png"> """icon" sizes="192x192" href="_static/icon/favicon-192x192.png" type="image/png"> """icon" sizes="512x512" href="_static/icon/favicon-512x512.png" type="image/png"> """apple-touch-icon" sizes="180x180" href="_static/icon/apple-touch-icon-180x180.png" type="image/png"> """mask-icon" href="_static/icon/safari-pinned-tab.svg" type="image/svg+xml">"""search" title="Search" href="search.html">"""next" title="Usage" href="usage.html">"""prev" title="Introduction" href="introduction.html"> """prefetch" href="_static/logo/logo-light.png" as="image"> """prefetch" href="_static/logo/logo-dark.png" as="image"> """stylesheet" type="text/css" href="_static/pygments.css?v=d111a655" /> """stylesheet" type="text/css" href="_static/styles/furo.css?v=4db3a74f" /> """stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=99069b78" /> """stylesheet" type="text/css" href="_static/styles.css?v=6deb019a" /> """stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/fontawesome.min.css" /> """stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/solid.min.css" /> """stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/brands.min.css" />
Skip to content
Flask-Session is switching serializer to msgspec in 1.0.0. Version 0.7.0 will migrate existing sessions upon read or write.
Back to top
View this page
Edit this page

# 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.