holoviews.core.io module#
Module defining input/output interfaces to HoloViews.
There are two components for input/output:
- ExportersProcess (composite) HoloViews objects one at a time. For
instance, an exporter may render a HoloViews object as a svg or perhaps pickle it.
- ArchivesA collection of HoloViews objects that are first collected
then processed together. For instance, collecting HoloViews objects for a report then generating a PDF or collecting HoloViews objects to dump to HDF5.
- class holoviews.core.io.Archive(*, exporters, name)[source]#
Bases:
Parameterized
An Archive is a means to collect and store a collection of HoloViews objects in any number of different ways. Examples of possible archives:
Generating tar or zip files (compressed or uncompressed).
Collating a report or document (e.g. PDF, HTML, LaTex).
Storing a collection of HoloViews objects to a database or HDF5.
Parameter Definitions
exporters = List(bounds=(0, None), default=[], label='Exporters')
The exporter functions used to convert HoloViews objects into the appropriate format(s).
- class holoviews.core.io.Deserializer(*, deserializer, name)[source]#
Bases:
Importer
A generic importer that supports any arbitrary de-serializer.
Parameter Definitions
deserializer = Callable(label='Deserializer')
The deserializer function, set to Store.load by default. The deserializer should take a file-like object that can be read from until the first object has been deserialized. If the file has not been exhausted, the deserializer should be able to continue parsing and loading objects. Any suitable deserializer may be used. For instance, pickle.load may be used although this will not load customized options.
- class holoviews.core.io.Exporter(*, info_fn, key_fn, name)[source]#
Bases:
ParameterizedFunction
An Exporter is a parameterized function that accepts a HoloViews object and converts it to a new some new format. This mechanism is designed to be very general so here are a few examples:
Pickling : Native Python, supported by HoloViews. Rendering : Any plotting backend may be used (default uses matplotlib) Storage : Saving to a database (e.g. SQL), HDF5 etc.
Parameter Definitions
key_fn = Callable(allow_None=True, label='Key fn')
Function that generates the metadata key from the HoloViews object being saved. The metadata key is a single high-dimensional key of values associated with dimension labels. The returned dictionary must have string keys and simple literals that may be conveniently used for dictionary-style indexing. Returns an empty dictionary by default.
info_fn = Callable(label='Info fn')
Function that generates additional metadata information from the HoloViews object being saved. Unlike metadata keys, the information returned may be unsuitable for use as a key index and may include entries such as the object’s repr. Regardless, the info metadata should still only contain items that will be quick to load and inspect.
- classmethod encode(entry)[source]#
Classmethod that applies conditional encoding based on mime-type. Given an entry as returned by __call__ return the data in the appropriate encoding.
- save(obj, basename, fmt=None, key=None, info=None, **kwargs)[source]#
Similar to the call method except saves exporter data to disk into a file with specified basename. For exporters that support multiple formats, the fmt argument may also be supplied (which typically corresponds to the file-extension).
The supplied metadata key and info dictionaries will be used to update the output of the relevant key and info functions which is then saved (if supported).
- class holoviews.core.io.FileArchive(*, archive_format, dimension_formatter, export_name, filename_formatter, flush_archive, max_filename, object_formatter, pack, root, timestamp_format, unique_name, exporters, name)[source]#
Bases:
Archive
A file archive stores files on disk, either unpacked in a directory or in an archive format (e.g. a zip file).
Parameter Definitions
exporters = List(bounds=(0, None), default=[<class 'holoviews.core.io.Pickler'>], label='Exporters')
The exporter functions used to convert HoloViews objects into the appropriate format(s).
dimension_formatter = String(default='{name}_{range}', label='Dimension formatter')
A string formatter for the output file based on the supplied HoloViews objects dimension names and values. Valid fields are the {name}, {range} and {unit} of the dimensions.
object_formatter = Callable(label='Object formatter')
Callable that given an object returns a string suitable for inclusion in file and directory names. This is what generates the value used in the {obj} field of the filename formatter.
filename_formatter = String(default='{dimensions},{obj}', label='Filename formatter')
A string formatter for output filename based on the HoloViews object that is being rendered to disk. The available fields are the {type}, {group}, {label}, {obj} of the holoviews object added to the archive as well as {timestamp}, {obj} and {SHA}. The {timestamp} is the export timestamp using timestamp_format, {obj} is the object representation as returned by object_formatter and {SHA} is the SHA of the {obj} value used to compress it into a shorter string.
timestamp_format = String(default='%Y_%m_%d-%H_%M_%S', label='Timestamp format')
The timestamp format that will be substituted for the {timestamp} field in the export name.
root = String(default='.', label='Root')
The root directory in which the output directory is located. May be an absolute or relative path.
archive_format = Selector(default='zip', label='Archive format', names={}, objects=['zip', 'tar'])
The archive format to use if there are multiple files and pack is set to True. Supported formats include ‘zip’ and ‘tar’.
pack = Boolean(default=False, label='Pack')
Whether or not to pack to contents into the specified archive format. If pack is False, the contents will be output to a directory. Note that if there is only a single file in the archive, no packing will occur and no directory is created. Instead, the file is treated as a single-file archive.
export_name = String(default='{timestamp}', label='Export name')
The name assigned to the overall export. If an archive file is used, this is the correspond filename (e.g. of the exporter zip file). Alternatively, if unpack=False, this is the name of the output directory. Lastly, for archives of a single file, this is the basename of the output file. The {timestamp} field is available to include the timestamp at the time of export in the chosen timestamp format.
unique_name = Boolean(default=False, label='Unique name')
Whether the export name should be made unique with a numeric suffix. If set to False, any existing export of the same name will be removed and replaced.
max_filename = Integer(bounds=(0, None), default=100, inclusive_bounds=(True, True), label='Max filename')
Maximum length to enforce on generated filenames. 100 is the practical maximum for zip and tar file generation, but you may wish to use a lower value to avoid long filenames.
flush_archive = Boolean(default=True, label='Flush archive')
Flushed the contents of the archive after export.
- add(obj=None, filename=None, data=None, info=None, **kwargs)[source]#
If a filename is supplied, it will be used. Otherwise, a filename will be generated from the supplied object. Note that if the explicit filename uses the {timestamp} field, it will be formatted upon export.
The data to be archived is either supplied explicitly as ‘data’ or automatically rendered from the object.
- object_formatter()[source]#
Simple name_generator designed for HoloViews objects.
Objects are labeled with {group}-{label} for each nested object, based on a depth-first search. Adjacent objects with identical representations yield only a single copy of the representation, to avoid long names for the common case of a container whose element(s) share the same group and label.
- class holoviews.core.io.Importer(*, name)[source]#
Bases:
ParameterizedFunction
An Importer is a parameterized function that accepts some data in some format and returns a HoloViews object. This mechanism is designed to be very general so here are a few examples:
Unpickling : Native Python, supported by HoloViews. Servers : Loading data over a network connection. Storage : Loading from a database (e.g. SQL), HDF5 etc.
Parameter Definitions
- class holoviews.core.io.Pickler(*, compress, protocol, info_fn, key_fn, name)[source]#
Bases:
Exporter
The recommended pickler for serializing HoloViews object to a .hvz file (a simple zip archive of pickle files). In addition to the functionality offered by Store.dump and Store.load, this file format offers three additional features:
Optional (zip) compression.
Ability to save and load components of a Layout independently.
Support for metadata per saved component.
The output file with the .hvz file extension is simply a zip archive containing pickled HoloViews objects.
Parameter Definitions
Parameters inherited from:
holoviews.core.io.Exporter
: key_fn, info_fnprotocol = Integer(default=2, inclusive_bounds=(True, True), label='Protocol')
The pickling protocol where 0 is ASCII, 1 supports old Python versions and 2 is efficient for new style classes.
compress = Boolean(default=True, label='Compress')
Whether compression is enabled or not
- save(obj, filename, key=None, info=None, **kwargs)[source]#
Similar to the call method except saves exporter data to disk into a file with specified basename. For exporters that support multiple formats, the fmt argument may also be supplied (which typically corresponds to the file-extension).
The supplied metadata key and info dictionaries will be used to update the output of the relevant key and info functions which is then saved (if supported).
- class holoviews.core.io.Reference(*, name)[source]#
Bases:
Parameterized
A Reference allows access to an object to be deferred until it is needed in the appropriate context. References are used by Collector to capture the state of an object at collection time.
One particularly important property of references is that they should be pickleable. This means that you can pickle Collectors so that you can unpickle them in different environments and still collect from the required object.
A Reference only needs to have a resolved_type property and a resolve method. The constructor will take some specification of where to find the target object (may be the object itself).
Parameter Definitions
- resolve(container=None)[source]#
Return the referenced object. Optionally, a container may be passed in from which the object is to be resolved.
- property resolved_type#
Returns the type of the object resolved by this references. If multiple types are possible, the return is a tuple of types.
- class holoviews.core.io.Serializer(*, file_ext, mime_type, serializer, info_fn, key_fn, name)[source]#
Bases:
Exporter
A generic exporter that supports any arbitrary serializer
Parameter Definitions
Parameters inherited from:
holoviews.core.io.Exporter
: key_fn, info_fnserializer = Callable(label='Serializer')
The serializer function, set to Store.dumps by default. The serializer should take an object and output a serialization as a string or byte stream. Any suitable serializer may be used. For instance, pickle.dumps may be used although this will not save customized options.
mime_type = String(allow_None=True, default='application/python-pickle', label='Mime type')
The mime-type associated with the serializer (if applicable).
file_ext = String(default='pkl', label='File ext')
The file extension associated with the corresponding file format (if applicable).
- save(obj, filename, info=None, key=None, **kwargs)[source]#
Similar to the call method except saves exporter data to disk into a file with specified basename. For exporters that support multiple formats, the fmt argument may also be supplied (which typically corresponds to the file-extension).
The supplied metadata key and info dictionaries will be used to update the output of the relevant key and info functions which is then saved (if supported).
- class holoviews.core.io.Unpickler(*, name)[source]#
Bases:
Importer
The inverse of Pickler used to load the .hvz file format which is simply a zip archive of pickle objects.
Unlike a regular pickle file, info and key metadata as well as individual components of a Layout may be loaded without needing to load the entire file into memory.
The components that may be individually loaded may be found using the entries method.
Parameter Definitions
- collect(files, drop=None, metadata=True)[source]#
Given a list or NdMapping type containing file paths return a Layout of Collators, which can be called to load a given set of files using the current Importer.
If supplied as a list each file is expected to disambiguate itself with contained metadata. If an NdMapping type is supplied additional key dimensions may be supplied as long as they do not clash with the file metadata. Any key dimension may be dropped by name by supplying a drop argument.
- holoviews.core.io.sanitizer(name, replacements=None)[source]#
String sanitizer to avoid problematic characters in filenames.
- holoviews.core.io.simple_name_generator(obj)[source]#
Simple name_generator designed for HoloViews objects.
Objects are labeled with {group}-{label} for each nested object, based on a depth-first search. Adjacent objects with identical representations yield only a single copy of the representation, to avoid long names for the common case of a container whose element(s) share the same group and label.