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(
    application,
    id_persister=obsession.CookieIdPersistence(cookie_name='mysession',
                                               max_age=86400,
                                               path='/my-site',
                                               domain='mysite.example.org'
                                               secure=True),
    backend=obsession.FileBackend(directory='/tmp/session-store',
                                  prefix='session_')
)

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 session.save() to ensure your changes are saved.

There are some useful extra properties and methods:

# Persist the session to the backend
session.save()

# What's my session id?
my_session_id = session.id

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

# 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']
s.load_id('my_session_id')

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

Project details


Download files

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

Source Distribution

obsession-1.2.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

obsession-1.2.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file obsession-1.2.2.tar.gz.

File metadata

  • Download URL: obsession-1.2.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for obsession-1.2.2.tar.gz
Algorithm Hash digest
SHA256 83a7e28108b6facc989f975d8805ed252539630a48ee8f2a944a62eb2a8955c2
MD5 3269830f91b2d0f377ee0de95544d118
BLAKE2b-256 f981ea08d12cfa7199e587fe39be41c3a07bb80e8845d8e5d825ebe926e8fc1f

See more details on using hashes here.

File details

Details for the file obsession-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: obsession-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for obsession-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 701e0c7b20124dc3ff0c687ce178427d98d272d6a777e68c2382f591f9041430
MD5 1925d157294b34fc25e9036961620456
BLAKE2b-256 03d417151249e1ad01229e2c0b5fb5ae4c474f41bcad5ce92e4b49e204ac8acd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page