Take the 2-minute tour ×

Am doing a project with Flask, Gevent and web socket using flask development server environment. I used flask_login. Here

  1. how can get i get the Unique Session ID for each connection?
  2. I want to store the SessionID in the Database and delete it once client disconnects.
  3. How to get total active connections

    from flask_login import * 
    login_manager = LoginManager()
    @app.route("/", methods=["GET", "POST"]) 
    def login():
        login_user([username], remember):    
    def logout(): 
share|improve this question
You want a session id for each connection or each logged in user? –  Burhan Khalid Mar 1 '13 at 11:04
hi Burhan, I need for each logged In User. Thanks in advance brother. –  user2104391 Mar 1 '13 at 11:26
How did you use flask_login? Post that part of your code. –  Burhan Khalid Mar 1 '13 at 11:32
Add the code to the question, not in the comment please. –  favoretti Mar 1 '13 at 11:51

1 Answer 1

There is no session id.

Sessions in Flask are simply wrappers over cookies. What you save on it it's digitally signed and sent as a cookie to the client. When you make a request, that cookie is sent to your server and then verified and transformed in a Python object.

AFAIK, Flask-Login saves on the session the user ID.

To get total active connections, you can:

  1. At login, generate an unique id and save it on the session (flask.session['uid'] = uuid.uuid4(), for example), then save it on your database.
  2. At logout, delete that unique id from the session (del flask.session['uid']) and also from your database.
  3. Retrieve the count of active sessions using your favourite method (ORM/Raw SQL)
share|improve this answer

Your Answer


