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(key)
Retrieve the access control list (ACL) for a specific key in the key-value store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key for which to retrieve the ACL. |
required |
Returns:
| Type | Description |
|---|---|
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(key, acls)
Add an entry to the access control list (ACL) for a specific key in the key-value store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key for which to add the ACL entry. |
required |
entity
|
str
|
The user or group to which the permission is granted. |
required |
permission
|
str
|
The permission to grant ('read' or 'write'). |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Example:
from datatailr import KV, ACL
kv = KV()
acls = ACL(read=["user1", "group1"], write=["user2"])
kv.add_acl("db_url", acls)
delete(key)
Delete a key-value pair from the key-value store by its key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the value to delete. |
required |
Returns: None Example:
from datatailr import KV
kv = KV()
kv.delete("db_url") # Deletes the key-value pair with key "db_url"
get(key)
Retrieve a value by its key from the key-value store. Note that different environments (dev/pre/prod) have separate key-value stores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the value to retrieve. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
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:
| Type | Description |
|---|---|
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(key, value, acl=None)
Store a key-value pair in the key-value store. Note that different environments (dev/pre/prod) have separate key-value stores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key under which to store the value. |
required |
value
|
str
|
The value to store. |
required |
acl
|
ACL
|
The access control list for the key-value pair. |
None
|
Returns:
| Type | Description |
|---|---|
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(key, acls)
Set the access control list (ACL) for a specific key in the key-value store, replacing any existing ACL entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key for which to set the ACL. |
required |
entity
|
str
|
The user or group for which to set the permission. |
required |
permission
|
str
|
The permission to set ('read' or 'write'). |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Example:
from datatailr import KV, ACL
kv = KV()
acls = ACL(read=["user1", "group1"], write=["user2"])
kv.set_acls("db_url", acls)