telegram.ext.DictPersistence

class telegram.ext.DictPersistence(store_user_data=True, store_chat_data=True, store_bot_data=True, user_data_json='', chat_data_json='', bot_data_json='', conversations_json='')

Bases: telegram.ext.basepersistence.BasePersistence

Using python’s dicts and json for making your bot persistent.

store_user_data

Whether user_data should be saved by this persistence class.

Type:bool
store_chat_data

Whether chat_data should be saved by this persistence class.

Type:bool
store_bot_data

Whether bot_data should be saved by this persistence class.

Type:bool
Parameters:
  • store_user_data (bool, optional) – Whether user_data should be saved by this persistence class. Default is True.
  • store_chat_data (bool, optional) – Whether user_data should be saved by this persistence class. Default is True.
  • store_bot_data (bool, optional) – Whether bot_data should be saved by this persistence class. Default is True .
  • user_data_json (str, optional) – Json string that will be used to reconstruct user_data on creating this persistence. Default is "".
  • chat_data_json (str, optional) – Json string that will be used to reconstruct chat_data on creating this persistence. Default is "".
  • bot_data_json (str, optional) – Json string that will be used to reconstruct bot_data on creating this persistence. Default is "".
  • conversations_json (str, optional) – Json string that will be used to reconstruct conversation on creating this persistence. Default is "".
bot_data

The bot_data as a dict

Type:dict
bot_data_json

The bot_data serialized as a JSON-string.

Type:str
chat_data

The chat_data as a dict

Type:dict
chat_data_json

The chat_data serialized as a JSON-string.

Type:str
conversations

The conversations as a dict

Type:dict
conversations_json

The conversations serialized as a JSON-string.

Type:str
get_bot_data()

Returns the bot_data created from the bot_data_json or an empty dict.

Returns:The restored user data.
Return type:defaultdict
get_chat_data()

Returns the chat_data created from the chat_data_json or an empty defaultdict.

Returns:The restored user data.
Return type:defaultdict
get_conversations(name)

Returns the conversations created from the conversations_json or an empty defaultdict.

Returns:The restored user data.
Return type:defaultdict
get_user_data()

Returns the user_data created from the user_data_json or an empty defaultdict.

Returns:The restored user data.
Return type:defaultdict
update_bot_data(data)

Will update the bot_data (if changed).

Parameters:data (dict) – The telegram.ext.dispatcher.bot_data.
update_chat_data(chat_id, data)

Will update the chat_data (if changed).

Parameters:
  • chat_id (int) – The chat the data might have been changed for.
  • data (dict) – The telegram.ext.dispatcher.chat_data [chat_id].
update_conversation(name, key, new_state)

Will update the conversations for the given handler.

Parameters:
  • name (str) – The handlers name.
  • key (tuple) – The key the state is changed for.
  • new_state (tuple | any) – The new state for the given key.
update_user_data(user_id, data)

Will update the user_data (if changed).

Parameters:
  • user_id (int) – The user the data might have been changed for.
  • data (dict) – The telegram.ext.dispatcher.user_data [user_id].
user_data

The user_data as a dict

Type:dict
user_data_json

The user_data serialized as a JSON-string.

Type:str