<!-- # hard line break macro for HTML -->

# fiftyone.operators.store.service

Execution store service.

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

**Classes:**

| [`ExecutionStoreService`](#fiftyone.operators.store.service.ExecutionStoreService)([repo, dataset_id, ...])   | Service for managing execution store operations.   |
|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------|

### *class* fiftyone.operators.store.service.ExecutionStoreService(repo: [ExecutionStoreRepo](fiftyone.factory.repos.execution_store.md#fiftyone.factory.repos.execution_store.ExecutionStoreRepo) | None = None, dataset_id: [ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId) | None = None, collection_name: str = None, notification_service: [ChangeStreamNotificationService](fiftyone.operators.store.notification_service.md#fiftyone.operators.store.notification_service.ChangeStreamNotificationService) | None = None)

Bases: `object`

Service for managing execution store operations.

Note that each instance of this service has a context:

- If a `dataset_id` is provided (or a `repo` associated with one),
  this instance operates on stores associated with that dataset
- If no `dataset_id` is provided (or a `repo` is provided that is not
  associated with one), this instance operates on stores that are not
  associated with a dataset

To operate on all stores across all contexts, use the `XXX_global()`
methods that this class provides.

* **Parameters:**
  * **repo** (*None*) – a
    [`fiftyone.factory.repos.execution_store.ExecutionStoreRepo`](fiftyone.factory.repos.execution_store.md#fiftyone.factory.repos.execution_store.ExecutionStoreRepo)
    If not provided, a new
    [`fiftyone.factory.repos.execution_store.MongoExecutionStoreRepo`](fiftyone.factory.repos.execution_store.md#fiftyone.factory.repos.execution_store.MongoExecutionStoreRepo)
    will be created
  * **dataset_id** (*None*) – a dataset ID (ObjectId) to scope operations to
  * **collection_name** (*None*) – a collection name to use for the execution
    store. If `repo` is provided, this argument is ignored
  * **notification_service** (*None*) – an optional notification service for the repository

**Methods:**

| [`create_store`](#fiftyone.operators.store.service.ExecutionStoreService.create_store)(store_name[, metadata, policy])            | Creates a new store with the specified name.                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| [`clear_cache`](#fiftyone.operators.store.service.ExecutionStoreService.clear_cache)([store_name])                                | Clears all cache entries in the execution stores.                                                 |
| [`get_store`](#fiftyone.operators.store.service.ExecutionStoreService.get_store)(store_name)                                      | Gets the specified store for the current context.                                                 |
| [`list_stores`](#fiftyone.operators.store.service.ExecutionStoreService.list_stores)()                                            | Lists all stores for the current context.                                                         |
| [`count_stores`](#fiftyone.operators.store.service.ExecutionStoreService.count_stores)()                                          | Counts the stores for the current context.                                                        |
| [`has_store`](#fiftyone.operators.store.service.ExecutionStoreService.has_store)(store_name)                                      | Determines whether the specified store exists in the current context.                             |
| [`delete_store`](#fiftyone.operators.store.service.ExecutionStoreService.delete_store)(store_name)                                | Deletes the specified store.                                                                      |
| [`set_key`](#fiftyone.operators.store.service.ExecutionStoreService.set_key)(store_name, key, value[, ttl, policy])               | Sets the value of a key in the specified store.                                                   |
| [`set_cache_key`](#fiftyone.operators.store.service.ExecutionStoreService.set_cache_key)(store_name, key, value[, ttl])           | Sets the value of a cache key in the specified store.                                             |
| [`set_key_if_absent`](#fiftyone.operators.store.service.ExecutionStoreService.set_key_if_absent)(store_name, key, value[, ...])   | Sets a key only when no value is already stored for it.                                           |
| [`compare_and_set_key`](#fiftyone.operators.store.service.ExecutionStoreService.compare_and_set_key)(store_name, key, ...[, ...]) | Atomically replaces a key whose value matches `expected`.                                         |
| [`has_key`](#fiftyone.operators.store.service.ExecutionStoreService.has_key)(store_name, key)                                     | Determines whether the specified key exists in the specified store.                               |
| [`get_key`](#fiftyone.operators.store.service.ExecutionStoreService.get_key)(store_name, key)                                     | Retrieves the value of a key from the specified store.                                            |
| [`delete_key`](#fiftyone.operators.store.service.ExecutionStoreService.delete_key)(store_name, key)                               | Deletes the specified key from the store.                                                         |
| [`update_ttl`](#fiftyone.operators.store.service.ExecutionStoreService.update_ttl)(store_name, key, new_ttl)                      | Updates the TTL of the specified key in the store.                                                |
| [`list_keys`](#fiftyone.operators.store.service.ExecutionStoreService.list_keys)(store_name)                                      | Lists all keys in the specified store.                                                            |
| [`count_keys`](#fiftyone.operators.store.service.ExecutionStoreService.count_keys)(store_name)                                    | Counts the keys in the specified store.                                                           |
| [`cleanup`](#fiftyone.operators.store.service.ExecutionStoreService.cleanup)()                                                    | Deletes all stores associated with the current context.                                           |
| [`has_store_global`](#fiftyone.operators.store.service.ExecutionStoreService.has_store_global)(store_name)                        | Determines whether a store with the given name exists across all datasets and the global context. |
| [`list_stores_global`](#fiftyone.operators.store.service.ExecutionStoreService.list_stores_global)()                              | Lists the stores across all datasets and the global context.                                      |
| [`count_stores_global`](#fiftyone.operators.store.service.ExecutionStoreService.count_stores_global)()                            | Counts the stores across all datasets and the global context.                                     |
| [`delete_store_global`](#fiftyone.operators.store.service.ExecutionStoreService.delete_store_global)(store_name)                  | Deletes the specified store across all datasets and the global context.                           |
| [`subscribe`](#fiftyone.operators.store.service.ExecutionStoreService.subscribe)(store_name, callback)                            | Subscribe to changes in a store.                                                                  |
| [`unsubscribe`](#fiftyone.operators.store.service.ExecutionStoreService.unsubscribe)(subscription_id)                             | Unsubscribe from changes in a store.                                                              |

#### create_store(store_name: str, metadata: dict[str, Any] | None = None, policy: str = 'persist') → [StoreDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.StoreDocument)

Creates a new store with the specified name.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  a `fiftyone.store.models.StoreDocument`

#### clear_cache(store_name=None) → None

Clears all cache entries in the execution stores.

#### get_store(store_name: str) → [StoreDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.StoreDocument)

Gets the specified store for the current context.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  a `fiftyone.store.models.StoreDocument`

#### list_stores() → [list](fiftyone.core.session.events.md#fiftyone.core.session.events.Colorscale.list)[str]

Lists all stores for the current context.

* **Returns:**
  a list of store names

#### count_stores() → int

Counts the stores for the current context.

* **Returns:**
  the number of stores

#### has_store(store_name) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Determines whether the specified store exists in the current
context.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  True/False

#### delete_store(store_name: str) → [StoreDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.StoreDocument)

Deletes the specified store.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  a `fiftyone.store.models.StoreDocument`

#### set_key(store_name: str, key: str, value: Any, ttl: int | None = None, policy: str = 'persist') → [KeyDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.KeyDocument)

Sets the value of a key in the specified store.

Keys can be either **persistent** or **cacheable**, depending on the provided
`policy` or whether a TTL (time-to-live) is set.

- If `policy="persist"` (default), the key will remain in the store until
  explicitly deleted.
- If `policy="evict"`, the key may be evicted by the system or manually
  removed using [`clear_cache()`](#fiftyone.operators.store.service.ExecutionStoreService.clear_cache).
- If a TTL is provided, the key is **always** treated as `policy="evict"`.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to set
  * **value** – the value to set
  * **ttl** (*None*) – an optional TTL in seconds
  * **policy** (*persist*) – the eviction policy for the key. Can be “persist” or “evict”.
    If “persist”, the key will never be automatically removed.
    If “evict”, the key may be removed automatically if a TTL is set,
    or manually via [`clear_cache()`](#fiftyone.operators.store.service.ExecutionStoreService.clear_cache).
* **Returns:**
  The created or updated key document.
* **Return type:**
  [KeyDocument](fiftyone.operators.store.md#fiftyone.operators.store.KeyDocument)

#### set_cache_key(store_name: str, key: str, value: Any, ttl: int | None = None) → [KeyDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.KeyDocument)

Sets the value of a cache key in the specified store.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to set
  * **value** – the value to set
  * **ttl** (*None*) – an optional TTL in seconds

#### set_key_if_absent(store_name: str, key: str, value: Any, ttl: int | None = None, policy: str = 'persist') → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Sets a key only when no value is already stored for it.

#### compare_and_set_key(store_name: str, key: str, expected: Any, value: Any, ttl: int | None = None, policy: str | None = None) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Atomically replaces a key whose value matches `expected`.

#### has_key(store_name: str, key: str) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Determines whether the specified key exists in the specified store.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to check

#### get_key(store_name: str, key: str) → [KeyDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.KeyDocument)

Retrieves the value of a key from the specified store.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to retrieve
* **Returns:**
  a `fiftyone.store.models.KeyDocument`

#### delete_key(store_name: str, key: str) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Deletes the specified key from the store.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to delete
* **Returns:**
  `True` if the key was deleted, `False` otherwise

#### update_ttl(store_name: str, key: str, new_ttl: int) → [KeyDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.KeyDocument)

Updates the TTL of the specified key in the store.

* **Parameters:**
  * **store_name** – the name of the store
  * **key** – the key to update the TTL for
  * **new_ttl** – the new TTL in seconds
* **Returns:**
  a `fiftyone.store.models.KeyDocument`

#### list_keys(store_name: str) → [list](fiftyone.core.session.events.md#fiftyone.core.session.events.Colorscale.list)[str]

Lists all keys in the specified store.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  a list of keys in the store

#### count_keys(store_name: str) → int

Counts the keys in the specified store.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  the number of keys in the store

#### cleanup() → None

Deletes all stores associated with the current context.

#### has_store_global(store_name: str) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Determines whether a store with the given name exists across all
datasets and the global context.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  True/False

#### list_stores_global() → [list](fiftyone.core.session.events.md#fiftyone.core.session.events.Colorscale.list)[[StoreDocument](fiftyone.operators.store.models.md#fiftyone.operators.store.models.StoreDocument)]

Lists the stores across all datasets and the global context.

* **Returns:**
  a list of `fiftyone.store.models.StoreDocument`

#### count_stores_global() → int

Counts the stores across all datasets and the global context.

* **Returns:**
  the number of stores

#### delete_store_global(store_name: str) → int

Deletes the specified store across all datasets and the global
context.

* **Parameters:**
  **store_name** – the name of the store
* **Returns:**
  the number of stores deleted

#### subscribe(store_name: str, callback: Callable[[str], None]) → str

Subscribe to changes in a store.

* **Parameters:**
  * **store_name** (*str*) – the name of the store to subscribe to
  * **callback** (*Callable* *[* *[**str* *]* *,* *None* *]*) – the callback to call when a change occurs
* **Returns:**
  the subscription ID
* **Return type:**
  str

#### unsubscribe(subscription_id: str) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Unsubscribe from changes in a store.

* **Parameters:**
  **subscription_id** (*str*) – the subscription ID to unsubscribe
* **Returns:**
  True if the subscription was removed, False otherwise
* **Return type:**
  [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)
