Sessions for the Google App Engine Python runtime
Project description
Features
Cookie based session for Google App Engine using the NDB datastore
- Configurable for the following cookie settings
Domain
Path
Secure
HttpOnly
Expires (timeout)
HMAC signature to verify cookie has not been tampered with
Autosave option which saves anytime a session value is modified
Optional Encryption of cookie data using AES
Custom timeout per session
Installation
Vishu is available on PyPi and we recommend installation via pip as a vendored package.
pip install -t libs vishnu
Alternatively download your preferred tagged release and all you should have to include is the vishnu folder.
Configuration
app.yaml
Vishnu will automatically look for and use the following variables from your app.yaml config.
Name |
Required |
Default |
Description |
---|---|---|---|
VISHNU_COOKIE_NAME |
no |
vishnu |
The name to use for the cookie. If omitted it omitted it will default vishnu |
VISHNU_SECRET |
yes |
N/A |
Secret used for HMAC signature |
VISHNU_ENCRYPT_KEY |
no |
N/A |
Key used to encrypt cookie data, it omitted then value will not be encrypted. |
VISHNU_DOMAIN |
no |
N/A |
The domain to set the cookie for. If omitted it will default to the domain the cookie was served from. |
VISHNU_PATH |
no |
/ |
The path to set the cookie for. If omitted it will default to /. |
VISHNU_SECURE |
no |
true |
Only send this cookie over SSL. |
VISHNU_HTTP_ONLY |
no |
true |
Only allow cookie access via HTTP/HTTPS. |
VISHNU_AUTO_SAVE |
no |
false |
Automatically save the session when a value is set. |
VISHNU_TIMEOUT |
no |
N/A |
How long until this cookie expires. If omitted it will last for the length of the browser session. |
Dependencies
If using encryption you will need to add the following to your app.yaml.
libraries:
- name: pycrypto
version: "2.6"
WSGI Middleware
To use vishnu you must add it as a middleware to your WSGI application.
from vishnu.middleware import SessionMiddleware
app = SessionMiddleware(app)
Setting a Custom Timeout
Each session uses the default timeout specified in app.yaml but if you want to have particular sessions differ to this you can do the following.
session = vishnu.get_session()
session.timeout = 3600
session.save()
The timeout is in seconds. To set the timeout to expire at the end of this session you can use the vishnu.session.TIMEOUT_SESSION constant.
session = vishnu.get_session()
session.timeout = vishnu.session.TIMEOUT_SESSION
session.save()
Cleaning up Expired Sessions
Add the following to a cron handler.
import vishnu
while not vishnu.delete_expired_sessions():
pass
You can alter the period after expired sessions are deleted by passing a value in seconds as dormant_for.
You can also alter the amount of sessions to delete per call using the limit argument.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for vishnu-1.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dd8c74f02743b18b9667122b3555422b7fdad8fb7dab46e2ae91348dc86da82 |
|
MD5 | bf34003b961b8c02287d5cb134fb70b0 |
|
BLAKE2b-256 | 1cd78f33ef1c1aa844ee1c6774ae36f72a012803e359cabc520816287321005d |