Python - kv()

Creates a new key value store to get, set, and delete key value pairs.

from nitric.resources import kv
from nitric.application import Nitric

profiles = kv('profiles').allow('getting', 'setting', 'deleting')

Nitric.run()

Parameters

  • Name
    name
    Required
    Required
    Type
    string
    Description

    The unique name of this key value store within the service. Subsequent calls to kv with the same name will return the same object.

Access

All Nitric resources provide access permissions you can use to specify the level of access your service needs to the resource. See here for details Access Control documentation.

Available permissions:


getting

This permission allows your service to get values from the key value store.


setting

This permission allows your service to set key value pairs in the key value store.


deleting

This permission allows your service to delete key value pairs in the key value store.


Examples

Create a key value store

from nitric.resources import kv
from nitric.application import Nitric

profiles = kv('profiles').allow('getting', 'setting', 'deleting')

Nitric.run()

Get value from a key value store

from nitric.resources import kv
from nitric.application import Nitric

profiles = kv('profiles').allow('getting')

profile = await profiles.get('profile-1a2b3c')

Nitric.run()

Set a key in a key value store

from nitric.resources import kv
from nitric.application import Nitric

profiles = kv('profiles').allow('setting')

await profiles.set('profile-1a2b3c', { 'name': 'John Smith' })

Nitric.run()

Delete a key from a key value store

from nitric.resources import kv
from nitric.application import Nitric

profiles = kv('profiles').allow('deleting')

await profiles.delete('profile-1a2b3c')

Nitric.run()