---
question: Are key-value keys shared across modules?
kind: overview
---

# Key-value store

The key-value store keeps small byte values by key, with an optional expiry. It is the kernel service `services.kv`: the engine hosts it, and modules reach it through `self.engine.services.kv` for shared state, sessions and flags. It is not a database: there are no queries beyond listing keys by prefix.

Super admins can browse, add, edit and delete keys in Nexus, under System › Data › Key-value. Compare and set is Python only.

<!-- matrix -->

## Backends

`services.kv` in `config.yaml` picks one adapter:

| Adapter | Storage | Used by |
|---|---|---|
| `python` | A SQLite file (`persistence_path`), or memory when it is not set | `config.yaml` of a new project (`abi dev up`), and the engine default |
| `redis` | A Redis server (`redis_url`) | `config.local.yaml` (Docker stack, port 6379) |
| `nats_rpc` | Another engine's store, over NATS | Engines that share one store |

A new project writes `persistence_path: storage/kv/python.sqlite3`; when the `kv:` block is missing, the engine uses the same file. The keys of each adapter are in the [Configuration Reference](/capabilities/get-started/configuration#key-value-store). On the Docker stack, Redis Commander browses Redis at `http://localhost:8082`.

## Key concepts

- **Bytes in, bytes out.** `set` takes `bytes` and `get` returns `bytes`. Encode text and JSON yourself.
- **One shared key space.** Keys are not prefixed with the module. Every module that declares the service sees the same keys, so prefix yours (`my_module:...`).
- **Expiry.** `ttl` is in seconds. An expired key reads as missing.
- **Atomic checks.** `set_if_not_exists` and `delete_if_value_matches` are atomic. There is no call that replaces a value only when the old one matches, and no lock: `kv.lock(...)` raises `NotImplementedError`.
- **Errors.** `get` and `delete` raise `KVNotFoundError` (`naas_abi_sdk.services.errors`) for a missing key.
- **Listing.** Listing keys and reading a key's remaining expiry go through the raw client, `self.engine.rpc.kv`: see [Store a value](/capabilities/build/platform/store-a-value?via=python).
- **Events.** Writes publish `KeyValueSet` and `KeyValueDeleted` when the engine's event service is up. A failed publish never fails the write.
- **Who else uses it.** The Jena TDB2 triple store adapter takes its write lock here, and the cache can use it as a tier (`keyvalue` adapter).
- **Dependency.** A module declares `"kv"` (or `"keyvalue"`) in `ModuleDependencies(services=(...))`. The attribute is `self.engine.services.kv`.
