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.3.tar.gz
(4.6 kB
view details)
File details
Details for the file tremolo-session-1.0.3.tar.gz
.
File metadata
- Download URL: tremolo-session-1.0.3.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 | 94a39a65eafc6996a9099387790c23f25d741343f39723ad3891b3316442a849 |
|
MD5 | 5d2ca0481a813934a3fa1fb385756ad7 |
|
BLAKE2b-256 | a06c0a2944c7a6c72bfe9db526a70e070d2f8ad3e35578a1de0c0babf810d7cf |