Skip to main content

Browser-aware flask session manager.

This module allows you to store any amount of data on session cookies without caring about browser-specific cookie limitations, by just registering session data shrink functions.

This module probably won’t play nicely with other cookies set on the same domain: session-cookie could be evicted at any time because other cookies and vice versa.

How it works

This module includes a simple browser cookie limit database, which is matched against flask request’s user agent and, on flask response, that information is used to serialize the session onto cookies.

This session implementation supports cookie signatures, multi-cookie session, and custom session shrinking logic which will be invoked when needed.

The session shrinking logic repeat this steps in order until session data fits into cookies:

  1. Registered shrinking functions, until they’re unable to reduce the cookie size.

  2. Unhandled keys are removed.

  3. Registered shrinking functions, now receiving True as parameter last.

  4. Remaining keys are removed.

Usage

This module works as a flask session interface, allowing to register session shrink functions which will be called once session does not fit on browser cookies.

import flask
import cookieman

app = flask.Flask(__name__)
app.session_interface = cookieman.CookieMan()
app.secret_key = 'my_app_secret_key'  # used for session cookie safety

@app.session_interface.register('a')
def shrink_a(data, last):
    '''
    Session property 'a' shrinking policy: remove last list item on key
    or just remove key.

    :param data: session data as dict
    :type data: Mapping[str, Any]
    :param last: wether is last iteration or not
    :type last: bool
    :returns: updated data (can be the same as received)
    :rtype: Mapping[str, Any]
    '''
    if len(data['a']) < 2:
        del data['a']
    else:
        data['a'].pop()
    return data

License

MIT (see LICENSE file).

Release files for cookieman 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cookieman 0.0.1
File Size Uploaded
cookieman-0.0.1.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cookieman 0.0.1
File Interpreter ABI Platform
cookieman-0.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 34.3 kB

Release files / cookieman-0.0.1.tar.gz

Download URL cookieman-0.0.1.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ba2c82fdfd9925a38faab230b4b3d489c2dd49332cbe67aa90492b1836c1d7e0
BLAKE2b-256 checksum
How to use checksums
cd8048707c7a27f66e931313b3a58bfe6496a0ef72d1bcef64dbae4948f43e23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release files / cookieman-0.0.1-py2.py3-none-any.whl

Download URL cookieman-0.0.1-py2.py3-none-any.whl
Size 18.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7f0b536a714d1fd806976843ea42b1f4b446b96295eba4a430b2fde7e2af9b4e
BLAKE2b-256 checksum
How to use checksums
35dfe51764ed0990385b5dab9fe804e9646bcd76a97f6876251d5602fec3d4cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

0.0.3

2 release files

0.0.2

2 release files

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page