omni.flux.feature_flags.core#

  • SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Licensed under the Apache License, Version 2.0 (the “License”);

  • you may not use this file except in compliance with the License.

  • You may obtain a copy of the License at

  • https://www.apache.org/licenses/LICENSE-2.0

  • Unless required by applicable law or agreed to in writing, software

  • distributed under the License is distributed on an “AS IS” BASIS,

  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  • See the License for the specific language governing permissions and

  • limitations under the License.

class omni.flux.feature_flags.core.FeatureFlag(key: str, settings_data: dict)#

Bases: object

property default_attr: dict[str, None]#
destroy()#
property display_name: str#
property key: str#
property tooltip: str#
property value: bool#
class omni.flux.feature_flags.core.FeatureFlagsCore#

Bases: object

feature_flags_changed(
callback: callable,
) list[SubscriptionId]#

A context manager to subscribe and unsubscribe from the feature_flags_changed events automatically.

Since the subscription will be cleaned up automatically when the context manager exits, this is not viable for long-running code, but can be useful in short-lived scripts.

Parameters:

callback – The callback to executed when the event is triggered.

Returns:

A list of subscription IDs created when subscribing to the events.

get_all_flags() list[FeatureFlag]#

Get all the feature flags defined in the /exts/omni.flux.feature_flags.core/flags settings.

This method will also clean up any residual persistent feature flag setting after transient definitions are removed.

Returns:

A list of FeatureFlag objects for every feature flag defined in the settings.

get_flag(
feature_flag_key: str,
) FeatureFlag#

Get a feature flag object, given its key

Parameters:

feature_flag_key – The key used in the settings to identify the feature flag

Raises:

ValueError – If the feature flag with the given key is not found in the settings.

Returns:

A FeatureFlag object of the feature flag requested

is_enabled(feature_flag_key: str) bool#

Whether a requested feature flag is enabled or not.

Parameters:

feature_flag_key – The key used in the settings to identify the feature flag

Raises:

ValueError – If the feature flag with the given key is not found in the settings.

Returns:

True if a feature flag is enabled, False otherwise.

set_enabled(feature_flag_key: str, value: bool)#

Set the requested feature flag’s value to the given value.

Parameters:
  • feature_flag_key – The key used in the settings to identify the feature flag

  • value – Whether the feature flag should be enabled or disabled.

set_enabled_all(value: bool)#

Set all the available feature flags’ values to the given value.

Parameters:

value – Whether the feature flags should be enabled or disabled.

subscribe_feature_flags_changed(
callback: callable,
) list[SubscriptionId]#

Subscribe to changes to any of the feature flags’ values.

Parameters:

callback – The callback function to be called when a feature flag’s value changes.

Returns:

A list of subscription IDs to use when unsubscribing.

unsubscribe_feature_flags_changed(
subscription_ids: list[SubscriptionId],
)#

Unsubscribe from the feature_flags_changed events.

Parameters:

subscription_ids – A list of subscription IDs to unsubscribe from