Redis Store extension for hug

pip install hug_store_redis==1.0.0



Build Status Coverage Status Scrutinizer Code Quality

hug_store_redis is a Redis store extension for the Python framework hug, which can be used as a session store.


Install via pip:

pip install hug_store_redis


This is how you create a Redis store:

from hug_store_redis import RedisStore
store = RedisStore(connection, namespace='sessions', expiration=3600)

The arguments are as follows:

  • connection: A connection object to the Redis server. This module installs the official redis module, but you can use your client of choice thanks to Python's duck typing. If you just want to get started quickly, use: import redis; connection = redis.StrictRedis().
  • namespace: A prefix for the keys which will be saved in Redis. If you choose sessions, the full key will be sessions:foobar.
  • expiration: Expiration time of each key in seconds. Will be reset on every store.set() call.

If you want to use this store with hug's session middleware, this is how:

middleware = SessionMiddleware(store)

Remember that the __hug__ object is only available after the first time a hug decorator has been executed.


The API implements the hug API for external stores.

  • set(key, data): JSON-encode data and save it for the given key.
  • get(key): JSON-decode data for the given key and return it. Raises hug.exceptions.StoreKeyNotFound if the key does not exist.
  • exists(key): Return whether the given key exists or not.
  • delete(key): Delete the given key.


hug_store_redis is written and maintained by Fabian Kochem.