Skip to main content

A simple, file-based session middleware for Tremolo.

Project description

tremolo-session

A simple, file-based session middleware for Tremolo.

See also: tremolo-login.

Usage

#!/usr/bin/env python3

from tremolo import Tremolo
from tremolo_session import Session

app = Tremolo()

# this is a session middleware
# that enables you to use context.session or request.context.session
Session(app, expires=86400)


@app.route('/')
async def index(request=None, **server):
    session = request.context.session

    if session is None:
        return b'The session will be created after you reload this page.'

    if 'visits' in session:
        session['visits'] += 1
    else:
        session['visits'] = 0

    return b'You have visited this page %d times today.' % session['visits']

if __name__ == '__main__':
    app.run('0.0.0.0', 8000, debug=True, reload=True)

Installing

python3 -m pip install --upgrade tremolo_session

Testing

Just run python3 alltests.py.

Or if you also want measurements with coverage:

coverage run alltests.py
coverage combine
coverage report
coverage html # to generate html reports

License

MIT

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

tremolo-session-1.0.5.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file tremolo-session-1.0.5.tar.gz.

File metadata

  • Download URL: tremolo-session-1.0.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for tremolo-session-1.0.5.tar.gz
Algorithm Hash digest
SHA256 004394d5a5f5455a4a1493bfd1d98c78d46439d5ac83d3f6766fdf962e73cd85
MD5 72ef6dacf38b490bc9043dbab162774a
BLAKE2b-256 d0283a53b5e864258fb8e57b94a1f8bdbd65be01b4cda42ab30144015d7f6e0b

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