The dictionary API

Vlermv create a dictionary-like object that is associated with a particular directory on your computer.

from vlermv import Vlermv
vlermv = Vlermv('/tmp/a-directory')

Items are files

The keys correspond to file names, and the values get serialized to files. The default serialization is pickle.

vlermv['filename'] = range(100)

import pickle
range(100) == pickle.load(open('/tmp/a-directory/filename', 'rb'))

(Default serialization is technically vlermv.serializers.pickle, but it’s pretty much the same thing as pickle.)

Get and delete

You can also get and delete things.

# Read
range(100) == vlermv['filename']

# Delete
del(vlermv['filename'])

Like a dictionary

And remember that vlermv is a dict-like object, so things like this work too.

vlermv.items()
vlermv.update({'a': 1, 'b': 2})

More options

There are several parameters that you can change when initializing Vlermv, and we’ll discuss those in later sections.

class vlermv.Vlermv(*directory, *, tempdir='.tmp', **kwargs)[source]

A dict API to a filesystem

Parameters:
  • directory (str) – Top-level directory of the vlermv
  • serializer (serializer) – A thing with dump and load functions for serializing and deserializing Python objects, like json, yaml, or anything in vlermv.serializers
  • key_transformer (key_transformer) – A thing with to_path and from_path functions for transforming keys to file paths and back. Several are available in vlermvtransformers.
  • mutable (bool) – Whether values can be updated and deleted
  • tempdir (str) – Subdirectory inside of base_directory to use for temporary files

These are mostly relevant for initialization via vlermv.cache.

Parameters:
  • appendable (bool) – Whether new values can be added to the Vlermv (Set this to False to ensure that the decorated function is never run and that the all results are cached; this is useful for reviewing old data in a read-only mode.)
  • cache_exceptions (bool) – If the decorated function raises an exception, should the failure and exception be cached? The exception is raised either way.
Raises:

TypeError – If cache_exceptions is True but the serializer can’t cache exceptions