I think the Flask-Session extension is what you are looking for.

Flask-Session is an extension for Flask that adds support for Server-side Session to your application.

From the linked website:

from flask import Flask, session
from flask_session import Session  # new style
# from flask.ext.session import Session  # old style

app = Flask(__name__)
# Check Configuration section for more details
SESSION_TYPE = 'redis'
app.config.from_object(__name__)
Session(app)

@app.route('/set/')
def set():
    session['key'] = 'value'
    return 'ok'

@app.route('/get/')
def get():
    return session.get('key', 'not set')
Answer from langlauf.io on Stack Overflow
🌐
TestDriven.io
testdriven.io › blog › flask-server-side-sessions
Server-side Sessions in Flask with Redis | TestDriven.io
December 15, 2023 - There are two types of sessions ... cookies · Server-side - sessions are stored server-side (typically a session identifier is then created and stored client-side in browser cookies)...
Top answer
1 of 3
12

I think the Flask-Session extension is what you are looking for.

Flask-Session is an extension for Flask that adds support for Server-side Session to your application.

From the linked website:

from flask import Flask, session
from flask_session import Session  # new style
# from flask.ext.session import Session  # old style

app = Flask(__name__)
# Check Configuration section for more details
SESSION_TYPE = 'redis'
app.config.from_object(__name__)
Session(app)

@app.route('/set/')
def set():
    session['key'] = 'value'
    return 'ok'

@app.route('/get/')
def get():
    return session.get('key', 'not set')
2 of 3
9

For flask-session 0.3.2, the documentation is here.

There are several available SESSION_TYPESs. filesystem is the most straightforward while you're testing. The expectation is you already have a Redis, database, etc. setup if you are going to use the other SESSION_TYPEs. Section on SESSION_TYPE and requirements

  • null: NullSessionInterface (default)
  • Redis: RedisSessionInterface
  • Memcached: MemcachedSessionInterface
  • filesystem: FileSystemSessionInterface
  • MongoDB: MongoDBSessionInterface
  • SQLAlchemy: SqlAlchemySessionInterface

Code example from the documentation. If you go to /set/ then the session['key'] is populated with the word 'value'. But if you go to /get/ first, then `session['key'] will not exist and it will return 'not set'.

from flask import Flask, session
from flask_session import Session

app = Flask(__name__)

app.config['SESSION_TYPE'] = 'filesystem'
#personal style preference compared to the first answer

Session(app)

@app.route('/set/')
def set():
    session['key'] = 'value'
    return 'ok'

@app.route('/get/')
def get():
    return session.get('key', 'not set')
🌐
TestDriven.io
testdriven.io › blog › flask-sessions
Sessions in Flask | TestDriven.io
June 4, 2023 - There are two types of sessions ... cookies · Server-side - sessions are stored server-side (typically a session identifier is then created and stored client-side in browser cookies)...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-use-flask-session-in-python-flask
How to use Flask-Session in Python Flask - GeeksforGeeks
March 24, 2025 - Sessions in Flask store user-specific data across requests, like login status, using cookies. Data is stored on the client side but signed with a secret key to ensure security. They help maintain user sessions without requiring constant ...
🌐
GitHub
github.com › pallets-eco › flask-session
GitHub - pallets-eco/flask-session: Server side session extension for Flask · GitHub
Flask-Session is an extension for Flask that adds support for server-side sessions to your application.
Starred by 534 users
Forked by 248 users
Languages   Python
🌐
Tech with Tim
techwithtim.net › tutorials › flask › sessions
Flask Tutorial - Sessions
Session: Is stored server side (on the web server) in a temporary directory. It is encrypted information and is a secure way to store information. Sessions are often used to store information that should not be seen by the user or should not be tampered with.
🌐
YouTube
youtube.com › pretty printed
Server-Side Sessions in Flask with Flask-Session - YouTube
Use Flask-Session to enable server-side sessions in Flask apps.WORK WITH ME👇🏼✅ Implement features and fix bugs in your app: Live, one-on-one screensharehtt...
Published   October 27, 2020
Views   27K
🌐
Readthedocs
flask-unchained.readthedocs.io › en › latest › tutorial › session.html
Server Side Sessions — Flask Unchained v0.9.0 documentation
By default, Flask will store user session information in a client-side cookie. This works, however, it has some drawbacks. For instance, it doesn’t allow sessions to be terminated by the server, implementation and user details get exposed in the cookie, and logout isn’t fully implemented ...
Find elsewhere
🌐
Readthedocs
flask-session.readthedocs.io › en › latest › config.html
Configuration - Flask-Session 0.8.0 documentation
Flask terminology regarding it’s built-in client-side session is inherited by Flask-Session: Permanent session: A cookie is stored in the browser and not deleted until it expires (has expiry). Also known as a persistent cookie. Non-permanent session: A cookie is stored in the browser and is deleted when the browser or tab is closed (no expiry). Also known as a session cookie or non-persistent cookie. Either cookie can be removed earlier if requested by the server...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › flask tutorial › flask session
Flask Session | How session works in Flask with Examples?
April 11, 2023 - Flask session is defined as a technique in flask utility that acts as an extension to provide support for sessions in the server-side in the flask application built. But, do we know what is Flask?
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Readthedocs
flask-session.readthedocs.io › en › latest › introduction.html
Introduction - Flask-Session 0.8.0 documentation
Flask-Session is an extension for Flask that adds support for server-side sessions to your application.
🌐
Spark Databox
sparkdatabox.com › tutorials › python-flask › flask-session
Flask Session
PHP uses the session id to retrieve session data and makes it available in your code by receiving upon a request from the client. This type of session is known as server-side sessions and the type of sessions Flask provides by default is known as client-side sessions.
🌐
DEV Community
dev.to › hackersandslackers › managing-session-data-with-flask-session-redis-360n
Managing Session Data with Flask-Session & Redis - DEV Community
February 12, 2020 - Flask-Session is a Flask plugin that enables the simple integration of a server-side cache leveraging methods such as Redis, Memcached, MongoDB, relational databases, and so forth.
🌐
GitHub
github.com › christopherpickering › flask-session2
GitHub - christopherpickering/flask-session2: Server side session extension for Flask · GitHub
Server side session extension for Flask. Contribute to christopherpickering/flask-session2 development by creating an account on GitHub.
Starred by 32 users
Forked by 7 users
Languages   Python 99.6% | Makefile 0.4%
🌐
Reddit
reddit.com › r/flask › how does flask session store sessions on server-side?
r/flask on Reddit: How does flask session store sessions on server-side?
February 24, 2020 -

From what I understand, flask sessions will create a browser cookie that is signed using the APP_SECRET.

When the client browser sends a request to the flask app, does the app check a datastore to validate the session? Or perhaps maybe the cookie in the request is validated without a datastore by using the APP_SECRET only?

Top answer
1 of 2
2
the server side usually packages up some session data (e.g user record, expiry-timestamp) as a string, then signs it using the secret. When the client passes back the cookie, the server can verify that it's a cookie generated by that server by checking the signature using the secret. The server can also see if the cookie is expired, who the cookie belongs to, etc by decoding the cookie using the secret and reading the content. If you have a lot of session data, you may want to store the session data in (e.g.) a database to keep from having to pass it back and forth all the time. There is a limit to how big a cookie can be, but it's pretty big (I'm guessing 64KB, it's been a while since I looked it up) if you set the domain of the cookie properly, then a bunch of independent servers in the same domain using the same cookie secret can share the session data. The cookie winds up carrying all of the state it needs within itself. The server is free to forget about the session until the next request comes in using the cookie, at which point everything it needs is taken from the cookie. The downside is that the cookie needs to be passed back and forth on every request, which makes it important that the cookie stay relatively small. Last thing to mention is that the server usually modifies the cookie (perhaps by changing the expiry time so that the cookie won't expire while the user remains active). The server is therefore rewriting the cookie on every request (or at least every few minutes of activity), and the cookie cache on the client keeps getting updated.
2 of 2
1
the cookie in the request is validated without a datastore by using the APP_SECRET only
🌐
Hackers and Slackers
hackersandslackers.com › flask-user-sessions-and-redis
Managing Session Data with Flask-Session & Redis
May 27, 2019 - Flask-Session is a Flask plugin that enables the simple integration of a server-side cache leveraging methods such as Redis, Memcached, MongoDB, relational databases, etc.
🌐
Python Geeks
pythongeeks.org › python geeks › learn flask › python flask session
Python Flask Session - Python Geeks
May 17, 2023 - Sessions allow you to store data on the server side and associate it with a particular user, making it accessible across multiple requests from the same user. Flask, a popular Python web framework, provides built-in support for managing sessions ...
🌐
GitHub
github.com › pallets-eco › flask-session › issues › 216
Signing server-side session: is it needed? · Issue #216 · pallets-eco/flask-session
March 4, 2024 - Flask-session (since 0.2) also allows you to do this setting SESSION_USE_SIGNER = True. As all of the data is stored in server-side storage rather than on the client cookie, all that is signed is the session id.
Author   pallets-eco
🌐
Compile N Run
compilenrun.com › flask tutorial › flask advanced features › flask server-side sessions
Flask Server-Side Sessions | Compile N Run
Here's a basic user authentication system using server-side sessions: ... from flask import Flask, session, redirect, url_for, request, render_template from flask_session import Session from werkzeug.security import generate_password_hash, check_password_hash app = Flask(__name__) app.config["SECRET_KEY"] = "your_secure_secret_key" app.config["SESSION_TYPE"] = "redis" app.config["SESSION_PERMANENT"] = True app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=1) Session(app) # Mock user database users = { "[email protected]": { "password": generate_password_hash("password123"), "name": "Te
🌐
DataFlair
data-flair.training › blogs › flask-session
How to Use Session in Flask? - DataFlair
July 27, 2023 - A Flask addon called Flask-Session allows your application to handle server-side sessions. The period of time between a client’s initial login and their final logout is known as a session.