API reference

class fridge.Fridge(path=None, file=None)[source]

Fridge is a subclass of dict and thus fully conforms to its interface.

Fridge keeps an open file until it’s closed, so you have to call close() when you’re done using it.

Fridge implements __enter__() and __exit__() so you can use with statement.

Parameters:
  • path – a path to a file that will be used to load and save the data
  • file – a file object that will be used to load and save the data. This file object in not closed by fridge automatically.

path and file arguments are mutually exclusive

close()[source]

Close the fridge. Calls save() and closes the underlying file object unless an already open file was passed to the constructor. This method has no effect if the file is already closed.

After the fridge is closed save() and load() will raise an exception but you will still be able to use it as an ordinary dictionary.

closed = None

True after close() is called, False otherwise.

load()[source]

Force reloading the data from the file. All data in the in-memory dictionary is lost. This method is called automatically by the constructor, normally you don’t need to call it.

save()[source]

Force saving the dictionary to the file. All data in the file is lost. This method is called automatically by close().

Previous topic

Welcome to Fridge’s documentation!