Skip to content

KV

A distributed key-value store for storing and retrieving configuration data, application settings, and other key-value pairs.

Note that different environments (dev/pre/prod) have separate key-value stores.

Each key-value pair can have its own access control list (ACL) to manage permissions for reading and writing.

Example:

from datatailr import KV, ACL, User, Group, Permission
kv = KV()
kv.put("db_url", "postgresql://user:password@host:port/dbname")
acls = ACL({Permission.READ: [User.get("user1"), Group.get("group1")],
            Permission.WRITE: [User.get("user2")]})
kv.add_acl("db_url", acls)
db_url = kv.get("db_url")
all_keys = kv.ls()
kv.delete("db_url")

acls

Retrieve the access control list (ACL) for a specific key in the key-value store.

Parameters:

  • key

    (str) –

    The key for which to retrieve the ACL.

Returns:

  • ACL

    dict[str, list[str]]: A dictionary containing lists of users/groups with 'read' and 'write' permissions.

Example:

from datatailr import KV
kv = KV()
acl = kv.acls("db_url")

add_acl

Add an entry to the access control list (ACL) for a specific key in the key-value store.

Parameters:

  • key

    (str) –

    The key for which to add the ACL entry.

  • acls

    (ACL) –

    The ACL to add.

Returns:

  • None

    None

Example:

from datatailr import KV, ACL, Permission, User, Group
kv = KV()
acls = ACL({Permission.READ: [User("user1"), Group("group1")],
            Permission.WRITE: [User("user2")]})
kv.add_acl("db_url", acls)

delete

Delete a key-value pair from the key-value store by its key.

Parameters:

  • key

    (str) –

    The key of the value to delete.

Returns: None Example:

from datatailr import KV
kv = KV()
kv.delete("db_url")  # Deletes the key-value pair with key "db_url"

get

Retrieve a value by its key from the key-value store. Note that different environments (dev/pre/prod) have separate key-value stores.

Parameters:

  • key

    (str) –

    The key of the value to retrieve.

Returns:

  • str ( str ) –

    The value associated with the key.

Example:

from datatailr import KV
kv = KV()
db_url = kv.get("db_url")

ls

List all keys stored in the key-value store for the current environment (dev/pre/prod).

Returns:

  • list[dict[str, str | ACL]]

    list[dict[str, str|ACL]]: A list of all keys in the key-value store along with their ACLs.

Example:

from datatailr import KV
kv = KV()
all_keys = kv.ls()

put

Store a key-value pair in the key-value store. Note that different environments (dev/pre/prod) have separate key-value stores.

Parameters:

  • key

    (str) –

    The key under which to store the value.

  • value

    (str) –

    The value to store.

  • acl

    (ACL, default: None ) –

    The access control list for the key-value pair.

Returns:

  • None

    None

Example:

from datatailr import KV, ACL, Permission, User, Group
kv = KV()
acls = ACL({Permission.READ: [User.get("user1"), Group.get("group1")],
            Permission.WRITE: [User.get("user2")]})
kv.put("db_url", "postgresql://user:password@host:port/dbname", acls)

set_acls

Set the access control list (ACL) for a specific key in the key-value store, replacing any existing ACL entries.

Parameters:

  • key

    (str) –

    The key for which to set the ACL.

  • acls

    (ACL) –

    The ACL to set.

Returns:

  • None

    None

Example:

from datatailr import KV, ACL, Permission, User, Group
kv = KV()
acls = ACL({Permission.READ: [User("user1"), Group("group1")],
            Permission.WRITE: [User("user2")]})
kv.set_acls("db_url", acls)