Skip to main content

Server-side HTTP sessions

Project description

Fast WSGI sessions. Zero dependencies. Python 3 ready.

Basic usage:

import obsession

application = obsession.SessionMiddleware(application)

Advanced usage:

# Customize all the options
application = obsession.SessionMiddleware(

Your application will now have a session object available in environ['ob.session'].

The session object acts like a regular dictionary:

session = environ['ob.session']
session['foo'] = 'bar'
session['bar'] = [1, 2, 3]

The session will be saved automatically whenever you mutate the session object itself - for example by assigning a new key, or reassigning an existing key. However if you change an already stored value then you should call to ensure your changes are saved.

There are some useful extra properties and methods:

# Persist the session to the backend

# What's my session id?
my_session_id =

# Cycle the session id.
# This generates a new session id and invalidates the old one.

# Load a session with a known id.
# Useful if you need to pass the session through another service that
# does not have access to the cookie.
s = environ['ob.session']

# Delete the session.
# This removes all data from the backend storage and deletes the client's
# session cookie

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for obsession, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size obsession-1.1.1-py3-none-any.whl (7.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size obsession-1.1.1.tar.gz (11.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page