API documentation¶
- class reprep.ReportInterface¶
- data(nid, data, mime='application/python', caption=None)¶
Attaches a data child to this node.
“data” is assumed to be a raw python structure. Or, if data is a string representing a file, pass a proper mime type (mime=’image/png’).
Returns a reference to the node being created.
Parameters: - caption (None|str) –
- mime (None|str) –
- nid (valid_id) –
- data_file(nid, mime, caption=None)¶
- Support for attaching data from a file. Note: this method is
supposed to be used in conjunction with the “with” construct.
For example, the following is the concise way to attach a pdf plot to a node.:
with report.data_file('my_plot', MIME_PDF) as f: pylab.figure() pylab.plot(x,y) pylab.title('my x-y plot') pylab.savefig(f)
Omit any file extension from ‘id’, (“my_plot” and not “my_plot.pdf”), we will take care of it for you.
This is a more complicated example, where we attach two versions of the same image, in different formats.
for format in [MIME_PDF, MIME_PNG]: with report.data_file('plot', format) as f: pylab.figure() pylab.plot(x,y) pylab.savefig(f) pylab.close()
Note that if you are mainly using pylab plots, there is the function plot() which offers a shortcut with less ceremonies.
Parameters: - caption (None|str) –
- mime (str) –
- nid (valid_id) –
- data_pylab(nid, mime=None, caption=None, **figure_args)¶
Same as plot(), but deprecated.
Parameters: - caption (None|str) –
- mime (None|str) –
- nid (None|valid_id) –
- data_rgb(nid, rgb, caption=None)¶
- Create a node containing an image from a RGB[a] array.
(internally, it will be saved as PNG)
rgb must be a height x width x 3 uint8 numpy array.
Parameters: - caption (None|str) –
- rgb (array[HxWx(3|4)](uint8)) –
- nid (valid_id|None) –
- figure(nid=None, cols=None, caption=None)¶
Attach a figure to this node.
Parameters: - caption (None|str) –
- cols (None|int,>=1) –
- nid (valid_id|None) –
- plot(nid=None, mime=None, caption=None, **figure_args)¶
- Easy support for creating a node consisting of a pylab plot.
Note: this method is supposed to be used in conjunction with the “with” construct.
For example, the following is the concise way to attach a plot:
with report.plot('my_plot') as pylab: pylab.plot(x,y) pylab.title('my x-y plot')
Basically, data_pylab allows you to save some lines of code more than with data_file().
You can pass **figure_args to pylab.figure().
Parameters: - caption (None|str) –
- mime (None|str) –
- nid (None|valid_id) –
- section(nid=None, caption=None)¶
Creates a subsection of the report. Returns a reference.
Parameters: nid (None|valid_id) –
- table(nid, data, cols=None, rows=None, caption=None)¶
Attach a table to this node.
:param:data: A list of lists, or a 2D numpy array. :param:colos: Labels for the columns. :param:rows: Labels for the rows.Parameters: - caption (None|str) –
- data (list(list)|array[HxW]) –
- nid (valid_id) –
- text(nid, text, mime='text/plain')¶
Adds a text node with the given id.
This is a very thin wrapper around data() that provides a default mime type (MIME_PLAIN).
For now, only restructured text is converted to HTML, the rest is displayed as plain text.
Parameters: - text (str) –
- mime (None|str) –
- nid (valid_id) –
- to_html(filename, resources_dir=None, **kwargs)¶
Creates a HTML representation of this report.