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