mpf.core.data_manager

Contains the DataManager base class.

class mpf.core.data_manager.DataManager(machine, name)

Handles key value data loading and saving for the machine.

Initialise data manger.

The DataManager is responsible for reading and writing data to/from a file on disk.

Parameters:
  • machine – The main MachineController instance.
  • name – A string name that represents what this DataManager instance is for. This name is used to lookup the configuration option in the machine config in the mpf:paths:<name> location. That’s how you specify the file name this DataManager will use.
get_data(section=None)

Return the value of this DataManager’s data.

Parameters:section – Optional string name of a section (dictionary key) for the data you want returned. Default is None which returns the entire dictionary.
remove_key(key)

Remove key by name.

save_all(data=None, delay_secs=0)

Write this DataManager’s data to the disk.

Parameters:
  • data – An optional dict() of the data you want to write. If None then it will write the data as it exists in its own data attribute.
  • delay_secs – Optional integer value of the amount of time you want to wait before the disk write occurs. Useful for writes that occur when MPF is busy, so you can delay them by a few seconds so they don’t slow down MPF. Default is 0.
save_key(key, value, delay_secs=0)

Update an individual key and then write the entire dictionary to disk.

Parameters:
  • key – String name of the key to add/update.
  • value – Value of the key
  • delay_secs – Optional number of seconds to wait before writing the data to disk. Default is 0.