Utility Methods

ChatterBot has a utility module that contains a collection of miscellaneous but useful functions.

Module imports


Imports the specified module based on the dot notated import path for the module.

Class initialization

chatterbot.utils.initialize_class(data, **kwargs)[source]
Parameters:data – A string or dictionary containing a import_path attribute.

Terminal input


Normalizes reading input between python 2 and 3. The function ‘raw_input’ becomes ‘input’ in Python 3.

NLTK corpus downloader


Download the specified NLTK corpus file unless it has already been downloaded.

Returns True if the corpus needed to be downloaded.

Stopword removal

chatterbot.utils.remove_stopwords(tokens, language)[source]

Takes a language (i.e. ‘english’), and a set of word tokens. Returns the tokenized text with any stopwords removed. Stop words are words like “is, the, a, ...”

Be sure to download the required NLTK corpus before calling this function: - from chatterbot.utils import nltk_download_corpus - nltk_download_corpus(‘corpora/stopwords’)

ChatBot response time


Returns the amount of time taken for a given chat bot to return a response.

Parameters:chatbot (ChatBot) – A chat bot instance.
Returns:The response time in seconds.
Return type:float

Random string generation

chatterbot.utils.generate_strings(total_strings, string_length=20)[source]

Generate a list of random strings.

  • total_strings (int) – The number of strings to generate.
  • string_length (int) – The length of each string to generate.

The generated list of random strings.

Return type:


Parsing datetime information

chatterbot.parsing.datetime_parsing(text, base_date=datetime.datetime(2017, 8, 8, 1, 43, 43, 789093))[source]

Extract datetime objects from a string of text.