Key Value Store

The store module lets allows you to persist any valid JSON data type across your function runs:

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null
from napkin import store

store.get(key)

Returns: dict

Retrieve the value associated with the key key. The value is returned in a dictionary with a single key, data.

store.put('myKey', 42)
x = store.get('myKey')
print(x)
# {'data': 42}

store.get_all()

Returns: dict

Retrieve all key-value pairs from the store, along with the store's total size in bytes. The return value is a dictionary with two keys, data and size.

store.put('candy', 'yum')
x = store.get_all()
print(x)
# {'data': {'candy': 'yum'}, 'size': 338}

store.has(key)

Returns: bool

Return whether or not the key-value store contains a key-value pair with key key.

store.put('myKey', 42)
print(store.has('myKey'))
# True

store.delete('myKey')
print(store.has('myKey'))
# False

print(store.get('myKey'))
# {'data': None}

store.put(key, value)

Returns: None

Save the given key-value pair in the Store. If the key-value pair already exists in the store, the value is updated accordingly.

store.put('myKey', 42)
print(store.has('myKey'))
# True

store.delete(key)

Delete the value stored under the key key.

store.put('myKey', 42)
print(store.has('myKey'))
# True

store.delete('myKey')
print(store.has('myKey'))
# False

print(store.get('myKey'))
# {'data': None}

store.size()

Returns: int

Return the current size in bytes of the key-value store. Maximum size is 400 KB.

print(store.size())
# 128