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)
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.2.tar.gz
(4.6 kB
view details)
File details
Details for the file tremolo-session-1.0.2.tar.gz
.
File metadata
- Download URL: tremolo-session-1.0.2.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9af11f82959174834b0d5129624e356e20f77522dd5b35622021a12ccff8c4c7 |
|
MD5 | 3b1f0730ccf266424ab954eff30f8f0d |
|
BLAKE2b-256 | 06cccd9e63f72c4347e76d2ab0b003067e881316b4539e6e3867cc6378d60bb5 |