API reference

class fridge.Fridge(path=None, file=None, dump_args=None, load_args=None)

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.
  • dump_args – dictionary of arguments that are passed to json.dump().
  • load_args – dictionary of arguments that are passed to json.load().

path and file arguments are mutually exclusive.

static Fridge.default_args

Arguments that are used if Fridge is called without path or file arguments. Example:

from fridge import Fridge

Fridge.default_args['path'] = '/home/user/.settings.conf'


with Fridge() as settings:
    settings['name'] = 'user'
close()

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 object 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()

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

classmethod readonly(*args, **kwargs)

Return an already closed read-only instance of Fridge. Arguments are the same as for the constructor.

save()

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

Previous topic

Welcome to Fridge’s documentation!

This Page