notice

This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).

Version: Main/Unreleased

rasa.utils.io

WriteRow Objects

class WriteRow(Protocol)

Describes a csv writer supporting a writerow method (workaround for typing).

writerow

def writerow(row: List[Text]) -> None

Write the given row.

Arguments:

  • row - the entries of a row as a list of strings

configure_colored_logging

def configure_colored_logging(loglevel: Text) -> None

Configures coloredlogs library for specified loglevel.

Arguments:

  • loglevel - The loglevel to configure the library for

enable_async_loop_debugging

def enable_async_loop_debugging(
event_loop: AbstractEventLoop,
slow_callback_duration: float = 0.1) -> AbstractEventLoop

Enables debugging on an event loop.

Arguments:

  • event_loop - The event loop to enable debugging on
  • slow_callback_duration - The threshold at which a callback should be alerted as slow.

pickle_dump

def pickle_dump(filename: Union[Text, Path], obj: Any) -> None

Saves object to file.

Arguments:

  • filename - the filename to save the object to
  • obj - the object to store

pickle_load

def pickle_load(filename: Union[Text, Path]) -> Any

Loads an object from a file.

Arguments:

  • filename - the filename to load the object from
  • Returns - the loaded object

create_temporary_file

def create_temporary_file(data: Any,
suffix: Text = "",
mode: Text = "w+") -> Text

Creates a tempfile.NamedTemporaryFile object for data.

create_temporary_directory

def create_temporary_directory() -> Text

Creates a tempfile.TemporaryDirectory.

create_path

def create_path(file_path: Text) -> None

Makes sure all directories in the 'file_path' exists.

file_type_validator

def file_type_validator(valid_file_types: List[Text],
error_message: Text) -> Type["Validator"]

Creates a Validator class which can be used with questionary to validate file paths.

not_empty_validator

def not_empty_validator(error_message: Text) -> Type["Validator"]

Creates a Validator class which can be used with questionary to validate that the user entered something other than whitespace.

create_validator

def create_validator(function: Callable[[Text], bool],
error_message: Text) -> Type["Validator"]

Helper method to create Validator classes from callable functions. Should be removed when questionary supports Validator objects.

json_unpickle

def json_unpickle(file_name: Union[Text, Path],
encode_non_string_keys: bool = False) -> Any

Unpickle an object from file using json.

Arguments:

  • file_name - the file to load the object from
  • encode_non_string_keys - If set to True then jsonpickle will encode non-string dictionary keys instead of coercing them into strings via repr().
  • Returns - the object

json_pickle

def json_pickle(file_name: Union[Text, Path],
obj: Any,
encode_non_string_keys: bool = False) -> None

Pickle an object to a file using json.

Arguments:

  • file_name - the file to store the object to
  • obj - the object to store
  • encode_non_string_keys - If set to True then jsonpickle will encode non-string dictionary keys instead of coercing them into strings via repr().

get_emoji_regex

def get_emoji_regex() -> Pattern

Returns regex to identify emojis.

are_directories_equal

def are_directories_equal(dir1: Path, dir2: Path) -> bool

Compares two directories recursively.

Files in each directory are assumed to be equal if their names and contents are equal.

Arguments:

  • dir1 - The first directory.
  • dir2 - The second directory.

Returns:

True if they are equal, False otherwise.