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

# fiftyone.core.state

Defines the shared state between the FiftyOne App and backend.

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

**Classes:**

| [`StateDescription`](#fiftyone.core.state.StateDescription)([color_scheme, config, ...])   | Class that describes the shared state between the FiftyOne App and a corresponding [`fiftyone.core.session.Session`](fiftyone.core.session.md#fiftyone.core.session.Session).   |
|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`SampleField`](#fiftyone.core.state.SampleField)(\*, ftype, path, subfield, ...)          |                                                                                                                                                                                 |

**Functions:**

| [`serialize_fields`](#fiftyone.core.state.serialize_fields)(schema)                           |    |
|-----------------------------------------------------------------------------------------------|----|
| [`build_color_scheme`](#fiftyone.core.state.build_color_scheme)([color_scheme, dataset, ...]) |    |

### *class* fiftyone.core.state.StateDescription(color_scheme=None, config=None, dataset=None, field_visibility_stage=None, group_id=None, group_slice=None, sample_id=None, selected=None, selected_labels=None, selected_samples=None, sample_selection_style=None, label_selection_style=None, spaces=None, view=None, view_name=None)

Bases: `Serializable`

Class that describes the shared state between the FiftyOne App and
a corresponding [`fiftyone.core.session.Session`](fiftyone.core.session.md#fiftyone.core.session.Session).

* **Parameters:**
  * **color_scheme** (*None*) – a [`fiftyone.core.odm.dataset.ColorScheme`](fiftyone.core.odm.dataset.md#fiftyone.core.odm.dataset.ColorScheme)
  * **config** (*None*) – an optional [`fiftyone.core.config.AppConfig`](fiftyone.core.config.md#fiftyone.core.config.AppConfig)
  * **dataset** (*None*) – the current [`fiftyone.core.dataset.Dataset`](fiftyone.core.dataset.md#fiftyone.core.dataset.Dataset)
  * **field_visibility_stage** (*None*) – a field visibility stage
  * **group_id** (*None*) – a [`fiftyone.core.groups.Group.id`](fiftyone.core.groups.md#fiftyone.core.groups.Group.id)
  * **group_slice** (*None*) – a [`fiftyone.core.groups.Group.name`](fiftyone.core.groups.md#fiftyone.core.groups.Group.name)
  * **sample_id** (*None*) – a `fiftyone.core.sample.Sample.id`
  * **selected_labels** (*None*) – the list of currently selected labels
  * **selected_samples** (*None*) – a list of dicts with sample selection info
  * **sample_selection_style** (*None*) – a dict mapping selection types to
    icon style names (e.g. `{"default": "checkmark", "alt": "thumbsdown"}`)
  * **label_selection_style** (*None*) – a dict mapping selection types to
    label selection style names (e.g. `{"default": "dashed", "alt": "dashed-red"}`)
  * **spaces** (*None*) – a [`fiftyone.core.odm.workspace.Space`](fiftyone.core.odm.workspace.md#fiftyone.core.odm.workspace.Space)
  * **view** (*None*) – the current [`fiftyone.core.view.DatasetView`](fiftyone.core.view.md#fiftyone.core.view.DatasetView)
  * **view_name** (*None*) – the name of the view if the current view is a
    saved view

**Methods:**

| [`attributes`](#fiftyone.core.state.StateDescription.attributes)()                                 | Returns a list of class attributes to be serialized.                                             |
|----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| [`serialize`](#fiftyone.core.state.StateDescription.serialize)([reflective])                       | Serializes the object into a dictionary.                                                         |
| [`from_dict`](#fiftyone.core.state.StateDescription.from_dict)(d)                                  | Constructs a [`StateDescription`](#fiftyone.core.state.StateDescription) from a JSON dictionary. |
| [`copy`](#fiftyone.core.state.StateDescription.copy)()                                             | Returns a deep copy of the object.                                                               |
| [`custom_attributes`](#fiftyone.core.state.StateDescription.custom_attributes)([dynamic, private]) | Returns a customizable list of class attributes.                                                 |
| [`from_json`](#fiftyone.core.state.StateDescription.from_json)(path, \*args, \*\*kwargs)           | Constructs a Serializable object from a JSON file.                                               |
| [`from_str`](#fiftyone.core.state.StateDescription.from_str)(s, \*args, \*\*kwargs)                | Constructs a Serializable object from a JSON string.                                             |
| [`get_class_name`](#fiftyone.core.state.StateDescription.get_class_name)()                         | Returns the fully-qualified class name string of this object.                                    |
| [`to_str`](#fiftyone.core.state.StateDescription.to_str)([pretty_print])                           | Returns a string representation of this object.                                                  |
| [`write_json`](#fiftyone.core.state.StateDescription.write_json)(path[, pretty_print])             | Serializes the object and writes it to disk.                                                     |

#### attributes()

Returns a list of class attributes to be serialized.

This method is called internally by `serialize()` to determine the
class attributes to serialize.

Subclasses can override this method, but, by default, all attributes in
vars(self) are returned, minus private attributes, i.e., those starting
with “_”. The order of the attributes in this list is preserved when
serializing objects, so a common pattern is for subclasses to override
this method if they want their JSON files to be organized in a
particular way.

* **Returns:**
  a list of class attributes to be serialized

#### serialize(reflective=True)

Serializes the object into a dictionary.

Serialization is applied recursively to all attributes in the object,
including element-wise serialization of lists and dictionary values.

* **Parameters:**
  **reflective** – whether to include reflective attributes when
  serializing the object. By default, this is False
* **Returns:**
  a JSON dictionary representation of the object

#### *classmethod* from_dict(d)

Constructs a [`StateDescription`](#fiftyone.core.state.StateDescription) from a JSON dictionary.

* **Parameters:**
  **d** – a JSON dictionary
* **Returns:**
  [`StateDescription`](#fiftyone.core.state.StateDescription)

#### copy()

Returns a deep copy of the object.

* **Returns:**
  a Serializable instance

#### custom_attributes(dynamic=False, private=False)

Returns a customizable list of class attributes.

By default, all attributes in vars(self) are returned, minus private
attributes (those starting with “_”).

* **Parameters:**
  * **dynamic** – whether to include dynamic properties, e.g., those defined
    by getter/setter methods or the `@property` decorator. By
    default, this is False
  * **private** – whether to include private properties, i.e., those
    starting with “_”. By default, this is False
* **Returns:**
  a list of class attributes

#### *classmethod* from_json(path, \*args, \*\*kwargs)

Constructs a Serializable object from a JSON file.

Subclasses may override this method, but, by default, this method
simply reads the JSON and calls from_dict(), which subclasses must
implement.

* **Parameters:**
  * **path** – the path to the JSON file on disk
  * **\*args** – optional positional arguments for `self.from_dict()`
  * **\*\*kwargs** – optional keyword arguments for `self.from_dict()`
* **Returns:**
  an instance of the Serializable class

#### *classmethod* from_str(s, \*args, \*\*kwargs)

Constructs a Serializable object from a JSON string.

Subclasses may override this method, but, by default, this method
simply parses the string and calls from_dict(), which subclasses must
implement.

* **Parameters:**
  * **s** – a JSON string representation of a Serializable object
  * **\*args** – optional positional arguments for `self.from_dict()`
  * **\*\*kwargs** – optional keyword arguments for `self.from_dict()`
* **Returns:**
  an instance of the Serializable class

#### *classmethod* get_class_name()

Returns the fully-qualified class name string of this object.

#### to_str(pretty_print=True, \*\*kwargs)

Returns a string representation of this object.

* **Parameters:**
  * **pretty_print** – whether to render the JSON in human readable format
    with newlines and indentations. By default, this is True
  * **\*\*kwargs** – optional keyword arguments for `self.serialize()`
* **Returns:**
  a string representation of the object

#### write_json(path, pretty_print=False, \*\*kwargs)

Serializes the object and writes it to disk.

* **Parameters:**
  * **path** – the output path
  * **pretty_print** – whether to render the JSON in human readable format
    with newlines and indentations. By default, this is False
  * **\*\*kwargs** – optional keyword arguments for `self.serialize()`

### *class* fiftyone.core.state.SampleField(\*, ftype: str, path: str, subfield: Optional[str], embedded_doc_type: Optional[str], db_field: Optional[str], description: Optional[str], info: Optional[<strawberry.types.scalar.ScalarWrapper object at 0x7f9de1ed2210>])

Bases: `object`

**Attributes:**

| [`ftype`](#fiftyone.core.state.SampleField.ftype)                         |    |
|---------------------------------------------------------------------------|----|
| [`path`](#fiftyone.core.state.SampleField.path)                           |    |
| [`subfield`](#fiftyone.core.state.SampleField.subfield)                   |    |
| [`embedded_doc_type`](#fiftyone.core.state.SampleField.embedded_doc_type) |    |
| [`db_field`](#fiftyone.core.state.SampleField.db_field)                   |    |
| [`description`](#fiftyone.core.state.SampleField.description)             |    |
| [`info`](#fiftyone.core.state.SampleField.info)                           |    |

#### ftype *: str*

#### path *: str*

#### subfield *: str | None*

#### embedded_doc_type *: str | None*

#### db_field *: str | None*

#### description *: str | None*

#### info *: <strawberry.types.scalar.ScalarWrapper object at 0x7f9de1ed2210> | None*

### fiftyone.core.state.serialize_fields(schema: Dict) → List[[SampleField](#fiftyone.core.state.SampleField)]

### fiftyone.core.state.build_color_scheme(color_scheme: [ColorScheme](fiftyone.core.odm.dataset.md#fiftyone.core.odm.dataset.ColorScheme) | None = None, dataset: [Dataset](fiftyone.core.dataset.md#fiftyone.core.dataset.Dataset) | None = None, app_config: [AppConfig](fiftyone.core.config.md#fiftyone.core.config.AppConfig) | None = None) → [ColorScheme](fiftyone.core.odm.dataset.md#fiftyone.core.odm.dataset.ColorScheme)
