Package: pyramid-kvs
Some Key Value Store basics for pyramid:Two KVS are implemented:memcacheredisHere are the provides features:An application cache, shared by every request.A session managerA rate limit per session holderA perl session reader (except you are migrating a perl website,
you probably don’t want to use it).Every of this components are optional, they exists if they are set in the
configuration like below.
Component settings are written in json.CacheThe application cache is a new attribute of the session.request.cacheif
the settingskvs.cacheexists.
Here are an example of configurationkvs.cache = {"kvs": "redis",
             "codec": "pickle",
             "kvs_kwargs": {},
             "ttl": 300,
             "key_prefix": "cache::"}Every kvs, except the type are optional.
The example contains every key with their default values for a redis instance.
Thekvs_kwargskey is passed to the driver to build the client connection.SessionThe session is accessible via “request.session”, it’s in every pyramid
application.
This is just an implementation for Key Value Store users.kvs.session = {"kvs": "redis",
               "key_name": "session_id",
               "session_type": "cookie",
                "ttl": 300,
                "key_prefix": "session::"}Every kvs, except the type are optional.
The example contains every key with their default values for a redis instance.You can also create a session for an http header like authentication token,
it’s help to create a cache per user in an API. API don’t use cookies.kvs.session = {"kvs": "redis",
               "key_name": "X-Auth-Token",
               "session_type": "header",
                "ttl": 300,
                "key_prefix": "session::"}RatelimitThe ratelimit works only if the kvs.session is used!
Ratelimit is per session hold and limit number of http queries in a defined
period.kvs.ratelimit = {"window": 1, "limit": 15}All keys are optional.
The example contains every key with their default values for a redis instance.If the ratelimit is enabled, every response will be decorated with the
following http headers:X-RateLimit-Limit: max queries in the period.X-RateLimit-Remaining: current remaining queries in that period.perlsessThis permit to read a session from a perl that usestorablesession.storable:http://search.cpan.org/~ams/Storable-2.45/Storable.pmHere is an example.# declare the perlsess
kvs.perlsess = {"type": "memcached"}Usage:Declare the addons in thepyramid.includesin your config, then
tweak the settings like above.# development.ini
[app:main]
pyramid.includes =
    pyramid_kvs

# declare the application cache
# except type, every keys are optional
# kvs_kwargs for redis is the parameters of the redis.Redis class
# see: http://redis-py.readthedocs.org/en/latest/
# for memcache, parameters of the memcache.Client class
# https://github.com/linsomniac/python-memcached/blob/master/memcache.py#L160
kvs.cache = {"type": "redis"}

# declare the session
kvs.session = {"type": "redis"}

# Authorize a session holder to do 20 http queries max in 2 seconds.
kvs.ratelimit = {"window": 2, "limit": 20}testspyramid_kvs have also a ‘mock’ implementation of akvsused for testing
purpose, register it using the pyramid plugins in your tests::::pyramid.includes =pyramid_kvs.testingChangelog0.4.1 (2019-03-12)Switch default serializer to json..warning:pickle serialize datetime by default, json don't, force the
serializer to pickle for backward compatibility in case datetime
are serialized0.4.0 (2019-02-18)Fix backward incompatibility of redis 3.xDrop support of redix 2.x branch0.3.1 (2019-02-22)Switch default serializer to json..warning::pickle serialize datetime by default, json don’t, force the
serializer to pickle for backward compatibility in case datetime
serialized0.3.0 (2018-03-15)Don’t freeze pyramid versionRemove support of python 2.60.2.3 (2015-09-14)Add get keys for Redis0.2.2 (2015-05-29)Bump version for PyPI upload problemsA file named “pyramid-kvs-0.2.1.tar.gz” already exists for  pyramid-kvs-0.2.1.
To fix problems with that file you should create a new release.0.2.1Improve testing0.2Add python 3 support0.1.1Fix package, files are missing0.1Initial version