Api Documentation¶
Sheet¶
The Sheet is the container holding the information, that is then accessed by one of the renderers. A sheet also represents an output directory in which caches and generated files are stored
- class datasheet.sheet.Sheet(out_dir_or_file: str, standalone=False)[source]¶
Main class of the library
- Parameters:
out (str) – The output directory or file.
standalone (bool) – If this option is set to
Truethe output will be a single file, In case of the HTMLRenderer that means images are encoded as base64.
- Variables:
type_wrap_map (dict) – Defines the mapping from input types to
ElementInterfaces. It is not possible to use tuple as key, as that will be ignored, because it is required for the special treatment theMultiCellInterface needs
- __lshift__(obj: Any)[source]¶
Object adding operator, automatically wraps passed objects into fitting type wrappers according to Sheet.type_wrap_map
- add_current_figure(clear: bool = True, **fig_args)[source]¶
Convinienve method to add the current figure, and optionally clear it afterwards.
- Parameters:
clear (bool) – whether or not to clear the figue
fig_args – forwarded to
Figure
- gate_cache(func, recompute, key=None)[source]¶
Wraps a function. The returned function will execute the wrapped function and store the results, if it does not find a saved result already. If recompute is True the wrapped function will also be executed if a saved result is found. If a stored result is found, and recompute is False the wrapped function will always return the stored result, independent of the calling parameters, or whether the source code of the cached function changed.
the key parameter determines the save file. By default the name of the wrapped function is used. In case of wanting to save multiple results for one function, it can be wrapped multiple times with different keys
Types¶
Every object that is added to a Sheet is wrapped in a Type-Object, which is derived
from ElementInterface . These classes purpose is to carry information on their
contained data. If a Type has a save_to_dir function it will be called when the
object is added to the sheet.
- class datasheet.types.DF(content: Any, rel_save_path: Path = None, dont_save: bool = False, save_format: str = 'tex')[source]¶
Pandas.DataFrame
- Parameters:
save_format (str) – supports to either save the dataframe as latex-table or csv-file. Valid values are “tex” and “csv”
- class datasheet.types.ElementInterface(content: Any, rel_save_path: Path = None, dont_save: bool = False)[source]¶
Base class for all other Interfaces.
To add an interface, 3 steps are neccessary:
- Define a class for it, which is derived from ElementInterface.
If it has a method named ‘_save_to_dir’ which takes one argument: the output directory, it will be called during
datasheet.sheet.Sheet.__lshift__. This way it is possible to save files, that can be used in the render-handlers.
Optionally define a mapping for a type to be wrapped automatically with your new interface by
datasheet.sheet.Sheet.__lshift__inSheet.type_wrap_map
- Parameters:
content (Any) – the actual element
rel_save_path (Path) – the output path in case a file should be stored, if not set, it can be assigned automatically using
ElementInterface.get_outfile
- class datasheet.types.Figure(content: Any, rel_save_path: Path = None, dont_save: bool = False, dpi: int = 300, bbox_inches: str = 'tight', transparent: bool = False, extension: str = 'png', scale: float = 0.7)[source]¶
matplotlib.pyplot.figure
All arguments except scale are passed to matplotlib.figure.Figure.save_fig.
- Parameters:
scale (float) – can be used by the renderer as a relative size
- class datasheet.types.HLayout(elems: List[any])[source]¶
Allows to use multiple elements in a Row. Takes a tuple as argument
- class datasheet.types.MD(content: Any, rel_save_path: Path = None, dont_save: bool = False, offset: dataclasses.InitVar[int] = -1)[source]¶
Markdown
- Parameters:
offset – the ammount of characters to strip of the left of each line. Determined automatically if set to -1.
- class datasheet.types.Repr(content: Any, rel_save_path: Path = None, dont_save: bool = False)[source]¶
Adds a repr() of the object
Renderer¶
Renderers are responsible for creating a final output file. Currentrly only the
html_renderer exists, which is automatically called by datasheet.sheet.Sheet.render
but to configure the render process it is also possible to call it manually like this:
renderer(sheet.entries, sheet.outdir, render_arg1, render_arg2)
- class datasheet.html_renderer.HTMLRenderer[source]¶
The Default renderer, that renders to HTML
- static render(entries: Layout, out_file: Path, style_sheet: str = 'default.css', max_index_len: int = 25)[source]¶
Renders a
Sheetas HTML-page.- Parameters:
outdir (Path) – The outputfolder to store the page in, usually
Sheet.outdir.style_sheet (str) – the css file to include in the page. It is looked for in datasheet.data, currently this is the only valid value for this parameter
max_index_len (int) – maximal number of characters a title can have before its index is abreviated.