Welcome to datasheet’s documentation!

Datasheet is a small library that aims to make it as easy as possible to generate nice, usable output files containing all sorts of information that might fall out of a scientific python script. The output is stored as html page. To a sheet you can easily add

  • Strings containing Markdown “code”
  • Pandas DataFrames
  • Nibabel nifti images
  • Matplotlib figures

with a single line. Think jupyter without source-code. To give a similar developing speed as you have in jupyter datasheet has two cache-functions, which will cache the results of a function call. The first one, datasheet.sheet.Sheet.cache is a wrapper around joblib.Memory The second one, datasheet.sheet.Sheet.gate_cache is pretty stupid, which can be handy too. The joblib cache is aware of the functions source-code and the arguments, and will rerun the function if one of these things changes. But it might very well be the case, that you want to change a thing in your source without instantly rerunning everything for very time consuming computations. The gated cache will ignore everything as long as there is already a stored result, and only recompute if it is explicitly told to do so.

After you added everything you want in your output file you simply call sheet.render() and an html file will be generated.

Installation via pip:

pip install datasheet

Here is an example:

from datasheet import Sheet, Repr, Str, MD
import pandas as pd
import matplotlib.pyplot as plt
import nibabel as nib
import numpy as np

def main():
    sheet = Sheet("./test_out")
    sheet << "# Test Title"
    sheet << """
    The reason that the title wasn't added as part of this
    multi line string is that if you add a sinle line string which
    contains a title, it will get an index entry.

    * With Bulletpoints
    * One more

    `And Some *RAW* MD Code`
    sheet << "## Next we have a Raw-String representation"
    raw_str = "Hello\nWorld"
    sheet << Repr(raw_str)
    sheet << "## And the same string printed"
    sheet << Str(raw_str)
    sheet << "## A Pandas table"
    sheet << """
        With a little demonstration of caching.
        (And this will be indented identically to the last MD Code
        Because there is auto indent detection)"""
    table = sheet.cache(compute_table)(20)
    sheet << HLayout((table.head(), """
        And Some *nice* MD comments Next to it.
        There is also a second type of cache, which you can access
        vial the gated_cache() method. But it's not used here.
        It is handy if you want to prevent recomputation under certain
    sheet << "### The Latex code:"
    sheet << Str(table.to_latex(index=False))
    sheet << "## A Matplotlib figure"
    plt.plot(table.x, table["x-sq"])
    sheet << "## We even have a nifti viewer"
    sheet << nib.load("tests/foo.nii")

def compute_table(x):
    return pd.DataFrame({
        "x": list(range(x)),
        "x-sq": [x**2 for x in range(x)]

def gaussian(x, mu, sig):
    return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))

def make_nifti():
    shape = np.array((50, 50, 50))
    dists = np.ones(shape)
    center = np.array((25, 25, 25))
    for index in np.ndindex(*shape):
        dists[index] = np.sqrt(np.sum((index - center) ** 2))
    return nib.Nifti1Image(gaussian(dists, 0, 10), np.eye(4))

if __name__ == "__main__":

which will produce the following html file:

You can find the details in the Api Documentation