fiftyone.core.state#

Defines the shared state between the FiftyOne App and backend.

Copyright 2017-2025, Voxel51, Inc.

Classes:

StateDescription([color_scheme, config, ...])

Class that describes the shared state between the FiftyOne App and a corresponding fiftyone.core.session.Session.

SampleField(*, ftype, path, subfield, ...)

Functions:

serialize_fields(schema)

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, 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.

Parameters:

Methods:

serialize([reflective])

Serializes the object into a dictionary.

attributes()

Returns a list of class attributes to be serialized.

from_dict(d)

Constructs a StateDescription from a JSON dictionary.

copy()

Returns a deep copy of the object.

custom_attributes([dynamic, private])

Returns a customizable list of class attributes.

from_json(path, *args, **kwargs)

Constructs a Serializable object from a JSON file.

from_str(s, *args, **kwargs)

Constructs a Serializable object from a JSON string.

get_class_name()

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

to_str([pretty_print])

Returns a string representation of this object.

write_json(path[, pretty_print])

Serializes the object and writes it to disk.

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

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

classmethod from_dict(d)#

Constructs a StateDescription from a JSON dictionary.

Parameters:

d – a JSON dictionary

Returns:

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 0x7d7dbe158450>])#

Bases: object

Attributes:

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 0x7d7dbe158450> | None#
fiftyone.core.state.serialize_fields(schema: Dict) List[SampleField]#
fiftyone.core.state.build_color_scheme(color_scheme: ColorScheme | None = None, dataset: Dataset | None = None, app_config: AppConfig | None = None) ColorScheme#