Store Library

These functions provide access to persistent, but not durable, storage.

 

Check out our Store doc for more information about the Medium One Store.

Import

To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import Store

 

Set global data

 

Store.set_global_data(keydatattl=0)

Sets the data for a global key.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to store
    • datastr|unicode data string to store
    • ttlint time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None
  • Example:
    • Sample Code:
      • import Store
        
        val = IONode.get_input('in1')['event_data']['value'] Store.set_global_data("max_value", str(val))


Set user data

Store.set_data(keydatattl=0)

Sets the data for a per-user key.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to store
    • datastr|unicode data string to store
    • ttlint time to live for the key in seconds. (-1 for infinite TTL, 0 for a week)
  • Returns: None
  • Example:
    • Sample Code
      • import Store

        val = IONode.get_input('in1')['event_data']['value']

        Store.set_data("my_max_value", str(val), -1)


Get global data

Store.get_global(key)

Get a previously stored global string.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to fetch
  • Returns:
    • unicode data string that was previously set, or None if the key had never been set, was deleted, or had timed out.
  • Example:
    • Sample Code:
      • import Store
        
        val = IONode.get_input('in1')['event_data']['value']
        
        max_value = Store.get_global("max_value")
        if max_value is None:
            max_value = val
        else:
            max_value = max(int(max_value), val)


Get user data

Store.get(key)

Get a previously stored per-user string.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to fetch
  • Returns:
    • unicode data string that was previously set, or None if the key had never been set, was deleted, or had timed out.
  • Example:
    • Sample Code:
      • import Store
        
        val = IONode.get_input('in1')['event_data']['value']
        
        max_value = Store.get("my_max_value")
        if max_value is None:
            max_value = val
        else:
            max_value = max(int(max_value), val)


Get global keys

Store.get_global_keys()

Get a list of active global keys.

  • Credit cost: 1
  • Returns:
    • set set of active global key names.
  • Example:
    • Sample Code:
      • import Store
        
        all_keys = Store.get_global_keys()
    • Return Value:
      • ["max_value", "test_key"]


Get user keys

Store.get_keys()

Get a list of active per-user keys. This is the list of the keys that have been set for all users. This does not indicate that the current user have values for these keys.

  • Credit cost: 1
  • Returns:
    • set set of active per user key names.
  • Example:
    • Sample Code:
      • import Store
        
        all_keys = Store.get_keys()
    • Return Value:
      • ["my_max_value", "test_key_1", "test_key_2"]


Get global TTL

Store.get_global_TTL(key)

Get the time to live (expiration time) of the given global key in seconds.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to get its TTL
  • Returns:
    • double time to live for the given global key in seconds
  • Example:
    • Sample Code:
      • import Store
        
        ttl = Store.get_global_TTL("max_value")
    • Return Value:
      • 600000


Get user TTL

Store.get_TTL(key) 

Get the time to live (expiration time) of the given per-user key in seconds.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to get its TTL
  • Returns:
    • double time to live for the given per-user key in seconds.
  • Example:
    • Sample Code:
      • import Store
        
        ttl = Store.get_TTL("my_max_value")
    • Return Value:
      • -1

 

Delete global key

Store.delete_global(key)

Deletes a global key, which reduces the number of keys counted against the global key quota. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to delete
  • Returns: None
  • Example:
    • Sample Code:
      • import Store

        Store.delete_global("max_value")


Delete user key

Store.delete(key)

Deletes a per-user key. Does nothing if the key had never been set or was already deleted.

  • Credit cost: 1
  • Parameters:
    • keystr|unicode name of key to delete
  • Returns: None
  • Example:
    • Sample Code:
      • import Store

        Store.delete("my_max_value")