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.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

obsession-1.2.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: obsession-1.2.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/63.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.16

File hashes

Hashes for obsession-1.2.1.tar.gz
Algorithm Hash digest
SHA256 d70428794ef195be6f22db673b2c6df895d4be11e4d98106d4855b039b64907b
MD5 e1554a42cc97b9d9ae64d87876ecee79
BLAKE2b-256 b7fccbab7f4b48e5bd5f7890571d5ce47ac5418141317d24ddede4e46186b8f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: obsession-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/63.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.16

File hashes

Hashes for obsession-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aee146659cee6e569f71d28dfc316e01e94a180f819910af95972c722699375a
MD5 37c9bdef763e92f614427a895ce88873
BLAKE2b-256 9e0f85bd23a146a83da71794a394b54c7e9d36d810a354c4173864e60c78481c

See more details on using hashes here.

Supported by

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