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).

Metadata

Release files for cookieman 0.0.3

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.3
File Size Uploaded Provenance
cookieman-0.0.3.tar.gz 16.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 39.5 kB

Release files / cookieman-0.0.3.tar.gz

Download URL cookieman-0.0.3.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
677fdf8430537bd40dda4b28af721c0ad652a7090433f83c29231caa063f8e8b
BLAKE2b-256 checksum
How to use checksums
b4865662528c72d2a4ce20034c82d03a07a6a6ca1a474de4e84b554290d2aa94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

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

Download URL cookieman-0.0.3-py2.py3-none-any.whl
Size 23.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4f8f67130b9af2e8e979c2fea03f9b513f7482084480650dcbfb7c07da68bc29
BLAKE2b-256 checksum
How to use checksums
ccf95e16054ba01d87f6cf6cabc52224aa37bc71ae678409fb262e314f44185a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

Security for cookieman 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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