notice

This is documentation for Rasa Open Source Documentation v2.0.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (2.1.x).

Version: 2.0.x

rasa.shared.utils.common

class_from_module_path

class_from_module_path(module_path: Text, lookup_path: Optional[Text] = None) -> Any

Given the module name and path of a class, tries to retrieve the class.

The loaded class can be used to instantiate new objects.

all_subclasses

all_subclasses(cls: Any) -> List[Any]

Returns all known (imported) subclasses of a class.

module_path_from_instance

module_path_from_instance(inst: Any) -> Text

Return the module path of an instance's class.

sort_list_of_dicts_by_first_key

sort_list_of_dicts_by_first_key(dicts: List[Dict]) -> List[Dict]

Sorts a list of dictionaries by their first key.

lazy_property

lazy_property(function: Callable) -> Any

Allows to avoid recomputing a property over and over.

The result gets stored in a local var. Computation of the property will happen once, on the first call of the property. All succeeding calls will use the value stored in the private property.

cached_method

cached_method(f: Callable[..., Any]) -> Callable[..., Any]

Caches method calls based on the call's args and kwargs.

Works for async and sync methods. Don't apply this to functions.

Arguments:

  • f - The decorated method whose return value should be cached.

Returns:

The return value which the method gives for the first call with the given arguments.

transform_collection_to_sentence

transform_collection_to_sentence(collection: Collection[Text]) -> Text

Transforms e.g. a list like ['A', 'B', 'C'] into a sentence 'A, B and C'.

minimal_kwargs

minimal_kwargs(kwargs: Dict[Text, Any], func: Callable, excluded_keys: Optional[List] = None) -> Dict[Text, Any]

Returns only the kwargs which are required by a function. Keys, contained in the exception list, are not included.

Arguments:

  • kwargs - All available kwargs.
  • func - The function which should be called.
  • excluded_keys - Keys to exclude from the result.

Returns:

Subset of kwargs which are accepted by func.

mark_as_experimental_feature

mark_as_experimental_feature(feature_name: Text) -> None

Warns users that they are using an experimental feature.

arguments_of

arguments_of(func: Callable) -> List[Text]

Return the parameters of the function func as a list of names.