module documentation

Utilities for documents.

Copyright 2017-2025, Voxel51, Inc.

Class DocumentRegistry A registry of fiftyone.core.odm.document.MongoEngineBaseDocument classes found when importing data from the database.
Exception DocumentRegistryError Error raised when an unknown document class is encountered.
Function create_field Creates the field defined by the given specification.
Function create_implied_field Creates the field for the given value.
Function deserialize_value Deserializes the given value.
Function get_field_kwargs Constructs the field keyword arguments dictionary for the given field.
Function get_implied_field_kwargs Infers the field keyword arguments dictionary for a field that can hold the given value.
Function load_dataset Loads the dataset from the database by its unique id or name. Throws an error if neither id nor name is provided.
Function serialize_value Serializes the given value.
Function validate_field_name Verifies that the given field name is valid.
Function validate_fields_match Validates that the types of the given fields match.
Variable fol Undocumented
Variable food Undocumented
Variable fooe Undocumented
Function _finalize_embedded_doc_fields Undocumented
Function _get_field_kwargs Undocumented
Function _get_field_type Undocumented
Function _get_list_subfield_type Undocumented
Function _merge_embedded_doc_fields Undocumented
Function _parse_embedded_doc_fields Undocumented
Function _parse_embedded_doc_list_fields Undocumented
Function _parse_field_str Undocumented
Variable _document_registry Undocumented
def create_field(name, ftype, embedded_doc_type=None, subfield=None, fields=None, db_field=None, description=None, info=None, read_only=False, created_at=None, **kwargs): (source)

Creates the field defined by the given specification.

Note

This method is used exclusively to create user-defined (non-default) fields. Any parameters accepted here must be stored on fiftyone.core.odm.dataset.SampleFieldDocument or else datasets will "lose" any additional decorations when they are loaded from the database.

Parameters
namethe field name
ftypethe field type to create. Must be a subclass of fiftyone.core.fields.Field
embedded_doc_type:Nonethe fiftyone.core.odm.BaseEmbeddedDocument type of the field. Only applicable when ftype is fiftyone.core.fields.EmbeddedDocumentField
subfield:Nonethe fiftyone.core.fields.Field type of the contained field. Only applicable when ftype is fiftyone.core.fields.ListField or fiftyone.core.fields.DictField
fields:Nonea list of fiftyone.core.fields.Field instances defining embedded document attributes. Only applicable when ftype is fiftyone.core.fields.EmbeddedDocumentField
db_field:Nonethe database field to store this field in. By default, name is used
description:Nonean optional description
info:Nonean optional info dict
read_only:Falsewhether the field should be read-only
created_at:Nonethe datetime the field was created
**kwargsUndocumented
Returns
a fiftyone.core.fields.Field
def create_implied_field(path, value, dynamic=False): (source)

Creates the field for the given value.

Parameters
paththe field name or path
valuea value
dynamic:Falsewhether to declare dynamic embedded document fields
Returns
a fiftyone.core.fields.Field
def deserialize_value(value): (source)

Deserializes the given value.

Parameters
valuethe serialized value
Returns
the value
def get_field_kwargs(field): (source)

Constructs the field keyword arguments dictionary for the given field.

Parameters
fielda fiftyone.core.fields.Field or str(field) representation of one
Returns
a field specification dict
def get_implied_field_kwargs(value, dynamic=False): (source)

Infers the field keyword arguments dictionary for a field that can hold the given value.

Parameters
valuea value
dynamic:Falsewhether to declare dynamic embedded document fields
Returns
a field specification dict
def load_dataset(id=None, name=None): (source)

Loads the dataset from the database by its unique id or name. Throws an error if neither id nor name is provided.

Parameters
id:Nonethe unique id of the dataset
name:Nonethe name of the dataset
Returns
a fiftyone.core.dataset.Dataset
def serialize_value(value, extended=False): (source)

Serializes the given value.

Parameters
valuethe value
extended:Falsewhether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format
Returns
the serialized value
def validate_field_name(field_name, media_type=None, is_frame_field=False): (source)

Verifies that the given field name is valid.

Parameters
field_namethe field name
media_type:Nonethe media type of the sample, if known
is_frame_field:Falsewhether this is a frame-level field
Raises
ValueErrorif the field name is invalid
def validate_fields_match(name, field, existing_field): (source)

Validates that the types of the given fields match.

Embedded document fields are not validated, if applicable.

Parameters
namethe field name or embedded.field.name
fielda fiftyone.core.fields.Field
existing_fieldthe reference fiftyone.core.fields.Field
Raises
ValueErrorif the fields do not match

Undocumented

Undocumented

Undocumented

def _finalize_embedded_doc_fields(fields_dict): (source)

Undocumented

def _get_field_kwargs(value, field, dynamic): (source)

Undocumented

def _get_field_type(value): (source)

Undocumented

def _get_list_subfield_type(values): (source)

Undocumented

def _merge_embedded_doc_fields(fields_dict, fields): (source)

Undocumented

def _parse_embedded_doc_fields(doc, dynamic): (source)

Undocumented

def _parse_embedded_doc_list_fields(values, dynamic): (source)

Undocumented

def _parse_field_str(field_str): (source)

Undocumented

_document_registry = (source)

Undocumented