fiftyone.operators¶
- fiftyone.operators.builtin
- fiftyone.operators.decorators
- fiftyone.operators.delegated
- fiftyone.operators.events
- fiftyone.operators.executor
- fiftyone.operators.message
- fiftyone.operators.operations
- fiftyone.operators.operator
- fiftyone.operators.panel
- fiftyone.operators.permissions
- fiftyone.operators.registry
- fiftyone.operators.server
- fiftyone.operators.types
- fiftyone.operators.utils
Module contents¶
FiftyOne operators.
Classes:
|
A FiftyOne operator. |
|
A configuration for an operator. |
|
Operator registry. |
|
Represents the execution context of an operator. |
|
Represents the execution options of an operation. |
|
A logging handler that reports all logging messages issued while the handler’s context manager is active to the provided execution context’s |
|
A panel. |
|
Configuration for a panel. |
Functions:
|
Gets the operator with the given URI. |
|
Returns all available operators. |
|
Checks if the given operator exists. |
|
Executes the operator with the given name. |
-
class
fiftyone.operators.
Operator
(_builtin=False)¶ Bases:
object
A FiftyOne operator.
Operators represent an operation and the details of how to execute it.
FiftyOne operators contain enough information for a user interface to render a form or button allowing a user to execute the operation.
Attributes:
The unique identifier of the operator:
plugin_name/operator_name
.Whether the operator is builtin.
The
OperatorConfig
for the operator.Methods:
resolve_delegation
(ctx)Returns the resolved forced delegation flag.
Returns the resolved execution options.
execute
(ctx)Executes the operator.
resolve_type
(ctx, type)Returns the resolved input or output property.
resolve_input
(ctx)Returns the resolved input property.
resolve_output
(ctx)Returns the resolved output property.
resolve_placement
(ctx)Returns the resolved placement of the operator.
method_to_uri
(method_name)Converts a method name to a URI.
to_json
()Returns a JSON representation of the operator.
add_secrets
(secrets)Adds secrets to the operator.
-
property
name
¶
-
property
uri
¶ The unique identifier of the operator:
plugin_name/operator_name
.
-
property
builtin
¶ Whether the operator is builtin.
-
property
config
¶ The
OperatorConfig
for the operator.
-
resolve_delegation
(ctx)¶ Returns the resolved forced delegation flag.
Subclasses can implement this method to decide if delegated execution should be forced for the given operation.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
whether the operation should be delegated (True), run immediately (False), or None to defer to
resolve_execution_options()
to specify the available options
-
resolve_execution_options
(ctx)¶ Returns the resolved execution options.
Subclasses can implement this method to define the execution options available for the operation.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.executor.ExecutionOptions
instance
-
execute
(ctx)¶ Executes the operator.
Subclasses must implement this method.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
JSON serializable data, or None
-
resolve_type
(ctx, type)¶ Returns the resolved input or output property.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
type – the type of property to resolve, either
"inputs"
or"outputs"
- Returns
a
fiftyone.operators.types.Property
, or None
-
resolve_input
(ctx)¶ Returns the resolved input property.
Subclasses can implement this method to define the inputs to the operator. This method should never be called directly. Instead use
resolve_type()
.By default, this method is called once when the operator is created. If the operator is dynamic, this method is called each time the input changes.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Property
, or None
-
resolve_output
(ctx)¶ Returns the resolved output property.
Subclasses can implement this method to define the outputs of the operator.
By default, this method is called once when the operator is created. If the operator is dynamic, this method is called after the operator is executed.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Property
, or None
-
resolve_placement
(ctx)¶ Returns the resolved placement of the operator.
Subclasses can implement this method to define the placement of the operator.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Placement
, or None
-
method_to_uri
(method_name)¶ Converts a method name to a URI.
- Parameters
method_name – the method name
- Returns
a URI
-
to_json
()¶ Returns a JSON representation of the operator.
- Returns
a JSON dict
-
add_secrets
(secrets)¶ Adds secrets to the operator.
- Parameters
secrets – a list of secrets
-
property
-
class
fiftyone.operators.
OperatorConfig
(name, label=None, description=None, dynamic=False, execute_as_generator=False, unlisted=False, on_startup=False, on_dataset_open=False, disable_schema_validation=False, delegation_target=None, icon=None, light_icon=None, dark_icon=None, allow_immediate_execution=True, allow_delegated_execution=False, default_choice_to_delegated=False, resolve_execution_options_on_change=None, **kwargs)¶ Bases:
object
A configuration for an operator.
- Parameters
name – the name of the operator
label (name) – a label for the operator
description (None) – a description of the operator
dynamic (False) – whether the operator inputs and outputs should be resolved when the input/output changes
execute_as_generator (False) – whether the operator should be executed as a generator
unlisted (False) – whether the operator should be hidden from the Operator Browser
on_startup (False) – whether the operator should be executed on startup
on_dataset_open (False) – whether the operator should be executed on opening a dataset
disable_schema_validation (False) – whether the operator built-in schema validation should be disabled
icon (None) – icon to show for the operator in the Operator Browser
light_icon (None) – icon to show for the operator in the Operator Browser when the App is in the light mode
dark_icon (None) – icon to show for the operator in the Operator Browser when the App is in the dark mode
allow_immediate_execution (True) – whether the operator should allow immediate execution
allow_delegated_execution (False) – whether the operator should allow delegated execution
default_choice_to_delegated (False) – whether to default to delegated execution, if allowed
resolve_execution_options_on_change (None) – whether to resolve execution options dynamically when inputs change. By default, this behavior will match the
dynamic
setting
Methods:
to_json
()-
to_json
()¶
-
class
fiftyone.operators.
OperatorRegistry
(enabled=True)¶ Bases:
object
Operator registry.
- enabled (True): whether to include only enabled operators (True) or
only disabled operators (False) or all operators (“all”)
Methods:
list_operators
([include_builtin, type])Lists the available FiftyOne operators.
Lists the errors that occurred during operator loading.
operator_exists
(operator_uri)Checks if the operator exists.
can_execute
(operator_uri)Whether the operator can be executed.
get_operator
(operator_uri)Retrieves an operator by its URI.
-
list_operators
(include_builtin=True, type=None)¶ Lists the available FiftyOne operators.
- Parameters
include_builtin (True) – whether to include builtin operators
type (None) – whether to include only
"panel"
or"operator"
type operators
- Returns
a list of
fiftyone.operators.Operator
instances
-
list_errors
()¶ Lists the errors that occurred during operator loading.
- Returns
a list of errors
-
operator_exists
(operator_uri)¶ Checks if the operator exists.
- Parameters
operator_uri – the URI of the operator
- Returns
True/False
-
can_execute
(operator_uri)¶ Whether the operator can be executed.
- Parameters
operator_uri – the URI of the operator
- Returns
True/False
-
get_operator
(operator_uri)¶ Retrieves an operator by its URI.
- Parameters
operator_uri – the URI of an operator
- Returns
an
fiftyone.operators.Operator
, or None
-
fiftyone.operators.
get_operator
(operator_uri, enabled=True)¶ Gets the operator with the given URI.
- Parameters
operator_uri – the operator URI
enabled (True) – whether to include only enabled operators (True) or only disabled operators (False) or all operators (“all”)
- Returns
- Raises
ValueError – if the operator is not found
-
fiftyone.operators.
list_operators
(enabled=True, type=None)¶ Returns all available operators.
- Parameters
enabled (True) – whether to include only enabled operators (True) or only disabled operators (False) or all operators (“all”)
type (None) – whether to include only
"panel"
or"operator"
type operators
- Returns
a list of
fiftyone.operators.Operator
instances
-
fiftyone.operators.
operator_exists
(operator_uri, enabled=True)¶ Checks if the given operator exists.
- Parameters
operator_uri – the operator URI
enabled (True) – whether to include only enabled operators (True) or only disabled operators (False) or all operators (“all”)
- Returns
True/False
-
fiftyone.operators.
execute_operator
(operator_uri, ctx=None, **kwargs)¶ Executes the operator with the given name.
- Parameters
operator_uri – the URI of the operator
ctx (None) –
a dictionary of parameters defining the execution context. The supported keys are:
dataset
: afiftyone.core.dataset.Dataset
or the name of a dataset to process. This is required unless aview
is providedview
(None): an optionalfiftyone.core.view.DatasetView
to processselected
([]): an optional list of selected sample IDsselected_labels
([]): an optional list of selected labels in the format returned byfiftyone.core.session.Session.selected_labels
current_sample
(None): an optional ID of the current sample being processedparams
: a dictionary of parameters for the operator. Consult the operator’s documentation for detailsrequest_delegation
(False): whether to request delegated execution, if supported by the operatordelegation_target
(None): an optional orchestrator on which to schedule the operation, if it is delegated
**kwargs – you can optionally provide any of the supported
ctx
keys as keyword arguments rather than including them inctx
- Returns
an
ExecutionResult
, or anasyncio.Task
if you run this method in a notebook context- Raises
ExecutionError – if an error occurred while immediately executing an operation or scheduling a delegated operation
-
class
fiftyone.operators.
ExecutionContext
(request_params=None, executor=None, set_progress=None, delegated_operation_id=None, operator_uri=None, required_secrets=None)¶ Bases:
object
Represents the execution context of an operator.
Operators can use the execution context to access the view, dataset, and selected samples, as well as to trigger other operators.
- Parameters
request_params (None) – a optional dictionary of request parameters
executor (None) – an optional
Executor
instanceset_progress (None) – an optional function to set the progress of the current operation
delegated_operation_id (None) – an optional ID of the delegated operation
operator_uri (None) – the unique id of the operator
required_secrets (None) – the list of required secrets from the plugin’s definition
Attributes:
The
fiftyone.core.dataset.Dataset
being operated on.The name of the
fiftyone.core.dataset.Dataset
being operated on.The ID of the
fiftyone.core.dataset.Dataset
being operated on.The
fiftyone.core.view.DatasetView
being operated on.Whether the operator has a custom view.
The list of selected sample IDs (if any).
A list of selected labels (if any).
The extended selection of the view (if any).
The ID of the current sample being processed (if any).
The ID of the user executing the operation, if known.
The request token authenticating the user executing the operation, if known.
The ID of the panel that invoked the operator, if any.
The current panel state.
A
fiftyone.operators.panel.PanelRef
instance that you can use to read and write the state and data of the current panel.Whether delegated execution has been forced for the operation.
Whether delegated execution has been requested for the operation.
The orchestrator to which the operation was delegated (if any).
A
dict
of results for the current operation.A read-only mapping of keys to their resolved values.
A
fiftyone.operators.operations.Operations
instance that you can use to trigger builtin operations on the current context.The current group slice of the view (if any).
Methods:
target_view
([param_name])The target
fiftyone.core.view.DatasetView
for the operator being executed.prompt
(operator_uri[, params, on_success, …])Prompts the user to execute the operator with the given URI.
secret
(key)Retrieves the secret with the given key.
resolve_secret_values
(keys, **kwargs)Resolves the values of the given secrets keys.
trigger
(operator_name[, params])Triggers an invocation of the operator with the given name.
log
(message)Logs a message to the browser console.
set_progress
([progress, label])Sets the progress of the current operation.
Serializes the execution context.
to_dict
()Returns the properties of the execution context as a dict.
-
property
dataset
¶ The
fiftyone.core.dataset.Dataset
being operated on.
-
property
dataset_name
¶ The name of the
fiftyone.core.dataset.Dataset
being operated on.
-
property
dataset_id
¶ The ID of the
fiftyone.core.dataset.Dataset
being operated on.
-
property
view
¶ The
fiftyone.core.view.DatasetView
being operated on.
-
target_view
(param_name='view_target')¶ The target
fiftyone.core.view.DatasetView
for the operator being executed.- Parameters
param_name ("view_target") – the name of the enum parameter defining the target view choice
- Returns
-
property
has_custom_view
¶ Whether the operator has a custom view.
-
property
selected
¶ The list of selected sample IDs (if any).
-
property
selected_labels
¶ A list of selected labels (if any).
Items are dictionaries with the following keys:
label_id
: the ID of the labelsample_id
: the ID of the sample containing the labelfield
: the field name containing the labelframe_number
: the frame number containing the label (only applicable to video samples)
-
property
extended_selection
¶ The extended selection of the view (if any).
-
property
current_sample
¶ The ID of the current sample being processed (if any).
When executed via the FiftyOne App, this is set when the user opens a sample in the modal.
-
property
user_id
¶ The ID of the user executing the operation, if known.
-
property
user_request_token
¶ The request token authenticating the user executing the operation, if known.
-
property
panel_id
¶ The ID of the panel that invoked the operator, if any.
-
property
panel_state
¶ The current panel state.
Only available when the operator is invoked from a panel.
-
property
panel
¶ A
fiftyone.operators.panel.PanelRef
instance that you can use to read and write the state and data of the current panel.Only available when the operator is invoked from a panel.
-
property
delegated
¶ Whether delegated execution has been forced for the operation.
-
property
requesting_delegated_execution
¶ Whether delegated execution has been requested for the operation.
-
property
delegation_target
¶ The orchestrator to which the operation was delegated (if any).
-
property
results
¶ A
dict
of results for the current operation.
-
property
secrets
¶ A read-only mapping of keys to their resolved values.
-
property
ops
¶ A
fiftyone.operators.operations.Operations
instance that you can use to trigger builtin operations on the current context.
-
property
group_slice
¶ The current group slice of the view (if any).
-
prompt
(operator_uri, params=None, on_success=None, on_error=None)¶ Prompts the user to execute the operator with the given URI.
- Parameters
operator_uri – the URI of the operator
params (None) – a dictionary of parameters for the operator
on_success (None) – a callback to invoke if the user successfully executes the operator
on_error (None) – a callback to invoke if the execution fails
- Returns
a
fiftyone.operators.message.GeneratedMessage
containing instructions for the FiftyOne App to prompt the user
-
secret
(key)¶ Retrieves the secret with the given key.
- Parameters
key – a secret key
- Returns
the secret value
-
async
resolve_secret_values
(keys, **kwargs)¶ Resolves the values of the given secrets keys.
- Parameters
keys – a list of secret keys
**kwargs – additional keyword arguments to pass to the secrets client for authentication if required
-
trigger
(operator_name, params=None)¶ Triggers an invocation of the operator with the given name.
This method is only available when the operator is invoked via the FiftyOne App. You can check this via
ctx.executor
.Example:
def execute(self, ctx): # Trigger the `reload_dataset` operator after this operator # finishes executing ctx.trigger("reload_dataset") # Immediately trigger the `reload_dataset` operator while a # generator operator is executing yield ctx.trigger("reload_dataset")
- Parameters
operator_name – the name of the operator
params (None) – a dictionary of parameters for the operator
- Returns
a
fiftyone.operators.message.GeneratedMessage
containing instructions for the FiftyOne App to invoke the operator
-
log
(message)¶ Logs a message to the browser console.
Note
This method is only available to non-delegated operators. You can only use this method during the execution of an operator.
- Parameters
message – a message to log
- Returns
a
fiftyone.operators.message.GeneratedMessage
containing instructions for the FiftyOne App to invoke the operator
-
set_progress
(progress=None, label=None)¶ Sets the progress of the current operation.
- Parameters
progress (None) – an optional float between 0 and 1 (0% to 100%)
label (None) – an optional label to display
-
serialize
()¶ Serializes the execution context.
- Returns
a JSON dict
-
to_dict
()¶ Returns the properties of the execution context as a dict.
-
class
fiftyone.operators.
ExecutionOptions
(allow_immediate_execution=True, allow_delegated_execution=False, default_choice_to_delegated=False)¶ Bases:
object
Represents the execution options of an operation.
- Parameters
allow_immediate_execution (True) – whether the operation can be executed immediately
allow_delegated_execution (False) – whether the operation can be delegated to an orchestrator
default_choice_to_delegated (False) – whether to default to delegated execution, if allowed
Attributes:
Methods:
update
([available_orchestrators])to_dict
()-
property
allow_immediate_execution
¶
-
property
allow_delegated_execution
¶
-
property
default_choice_to_delegated
¶
-
property
available_orchestrators
¶
-
property
orchestrator_registration_enabled
¶
-
update
(available_orchestrators=None)¶
-
to_dict
()¶
-
class
fiftyone.operators.
ProgressHandler
(ctx, logger=None, level=None)¶ Bases:
logging.Handler
A logging handler that reports all logging messages issued while the handler’s context manager is active to the provided execution context’s
set_progress()
method.- Parameters
ctx – an
fiftyone.operators.executor.ExecutionContext
logger (None) – a specific
logging.Logger
for which to report records. By default, the root logger is usedlevel (None) – an optional logging level above which to report records. By default, the logger’s effective level is used
Methods:
emit
(record)Do whatever it takes to actually log the specified logging record.
acquire
()Acquire the I/O thread lock.
addFilter
(filter)Add the specified filter to this handler.
close
()Tidy up any resources used by the handler.
Acquire a thread lock for serializing access to the underlying I/O.
filter
(record)Determine if a record is loggable by consulting all the filters.
flush
()Ensure all logging output has been flushed.
format
(record)Format the specified record.
get_name
()handle
(record)Conditionally emit the specified logging record.
handleError
(record)Handle errors which occur during an emit() call.
release
()Release the I/O thread lock.
removeFilter
(filter)Remove the specified filter from this handler.
setFormatter
(fmt)Set the formatter for this handler.
setLevel
(level)Set the logging level of this handler.
set_name
(name)Attributes:
-
emit
(record)¶ Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
-
acquire
()¶ Acquire the I/O thread lock.
-
addFilter
(filter)¶ Add the specified filter to this handler.
-
close
()¶ Tidy up any resources used by the handler.
This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.
-
createLock
()¶ Acquire a thread lock for serializing access to the underlying I/O.
-
filter
(record)¶ Determine if a record is loggable by consulting all the filters.
The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero.
Changed in version 3.2: Allow filters to be just callables.
-
flush
()¶ Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by subclasses.
-
format
(record)¶ Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter for the module.
-
get_name
()¶
-
handle
(record)¶ Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.
-
handleError
(record)¶ Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method.
-
property
name
¶
-
release
()¶ Release the I/O thread lock.
-
removeFilter
(filter)¶ Remove the specified filter from this handler.
-
setFormatter
(fmt)¶ Set the formatter for this handler.
-
setLevel
(level)¶ Set the logging level of this handler. level must be an int or a str.
-
set_name
(name)¶
-
class
fiftyone.operators.
Panel
(_builtin=False)¶ Bases:
fiftyone.operators.operator.Operator
A panel.
Methods:
render
(ctx)Defines the panel’s layout and events.
resolve_input
(ctx)Returns the resolved input property.
on_startup
(ctx)on_load
(ctx)execute
(ctx)Executes the operator.
add_secrets
(secrets)Adds secrets to the operator.
method_to_uri
(method_name)Converts a method name to a URI.
resolve_delegation
(ctx)Returns the resolved forced delegation flag.
Returns the resolved execution options.
resolve_output
(ctx)Returns the resolved output property.
resolve_placement
(ctx)Returns the resolved placement of the operator.
resolve_type
(ctx, type)Returns the resolved input or output property.
to_json
()Returns a JSON representation of the operator.
Attributes:
Whether the operator is builtin.
The
OperatorConfig
for the operator.The unique identifier of the operator:
plugin_name/operator_name
.-
render
(ctx)¶ Defines the panel’s layout and events.
This method is called after every panel event is called (on load, button callback, context change event, etc).
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
-
resolve_input
(ctx)¶ Returns the resolved input property.
Subclasses can implement this method to define the inputs to the operator. This method should never be called directly. Instead use
resolve_type()
.By default, this method is called once when the operator is created. If the operator is dynamic, this method is called each time the input changes.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Property
, or None
-
on_startup
(ctx)¶
-
on_load
(ctx)¶
-
execute
(ctx)¶ Executes the operator.
Subclasses must implement this method.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
JSON serializable data, or None
-
add_secrets
(secrets)¶ Adds secrets to the operator.
- Parameters
secrets – a list of secrets
-
property
builtin
¶ Whether the operator is builtin.
-
property
config
¶ The
OperatorConfig
for the operator.
-
method_to_uri
(method_name)¶ Converts a method name to a URI.
- Parameters
method_name – the method name
- Returns
a URI
-
property
name
¶
-
resolve_delegation
(ctx)¶ Returns the resolved forced delegation flag.
Subclasses can implement this method to decide if delegated execution should be forced for the given operation.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
whether the operation should be delegated (True), run immediately (False), or None to defer to
resolve_execution_options()
to specify the available options
-
resolve_execution_options
(ctx)¶ Returns the resolved execution options.
Subclasses can implement this method to define the execution options available for the operation.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.executor.ExecutionOptions
instance
-
resolve_output
(ctx)¶ Returns the resolved output property.
Subclasses can implement this method to define the outputs of the operator.
By default, this method is called once when the operator is created. If the operator is dynamic, this method is called after the operator is executed.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Property
, or None
-
resolve_placement
(ctx)¶ Returns the resolved placement of the operator.
Subclasses can implement this method to define the placement of the operator.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
- Returns
a
fiftyone.operators.types.Placement
, or None
-
resolve_type
(ctx, type)¶ Returns the resolved input or output property.
- Parameters
ctx – the
fiftyone.operators.executor.ExecutionContext
type – the type of property to resolve, either
"inputs"
or"outputs"
- Returns
a
fiftyone.operators.types.Property
, or None
-
to_json
()¶ Returns a JSON representation of the operator.
- Returns
a JSON dict
-
property
uri
¶ The unique identifier of the operator:
plugin_name/operator_name
.
-
-
class
fiftyone.operators.
PanelConfig
(name, label, help_markdown=None, icon=None, light_icon=None, dark_icon=None, allow_multiple=False, surfaces: typing_extensions.Literal[grid, modal, grid modal] = 'grid', **kwargs)¶ Bases:
fiftyone.operators.operator.OperatorConfig
Configuration for a panel.
- Parameters
name – the name of the panel
label – the display name for the panel
icon (None) – the icon to show in the panel’s tab
light_icon (None) – the icon to show in the panel’s tab when the App is in light mode
dark_icon (None) – the icon to show in the panel’s tab when the App is in dark mode
allow_multiple (False) – whether to allow multiple instances of the panel to be opened
surfaces ("grid") – the surfaces on which the panel can be displayed
help_markdown (None) – a markdown string to display in the panel’s help tooltip
Methods:
to_json
()-
to_json
()¶