tensorstore.KvStore.write(self, key: str, value: str | None, *, if_equal: str | None = None) Future[KvStore.TimestampedStorageGeneration]

Writes or deletes a single key.

Example

>>> store = await ts.KvStore.open({'driver': 'memory'})
>>> await store.write(b'a', b'value')
KvStore.TimestampedStorageGeneration(...)
>>> await store.read(b'a')
KvStore.ReadResult(state='value', value=b'value', stamp=KvStore.TimestampedStorageGeneration(...))
>>> await store.write(b'a', None)
KvStore.TimestampedStorageGeneration(...)
>>> await store.read(b'a')
KvStore.ReadResult(state='missing', value=b'', stamp=KvStore.TimestampedStorageGeneration(...))
Parameters:
key: str

Key to write/delete. This is appended (without any separator) to the existing path, if any.

value: str | None

Value to store, or None to delete.

if_equal: str | None = None

If specified, indicates a conditional write operation. The write is performed only if the existing generation associated with key matches if_equal.

Returns:

  • If no transaction is specified, returns a Future that resolves to the new storage generation for key once the write operation completes and durability is guaranteed (to the extent supported by the driver).

  • If a transaction is specified, returns a Future that resolves to an empty storage generation once the write operation is recorded in the transaction. The write operation is not actually performed until the transaction is committed.