Capture cell facts

  • The Cell Facts feature in the notebook allows direct capturing of cell outputs, such as print statements, tables, and images, and automatically saves them into HTML snippets. These HTML files can be easily uploaded as attachments, appearing as inline-rendered content in the UI, without the need for additional ‘save to file’ statements

Magic command: %%capture_cell_facts

Important

  • Using capture_cell_facts magic command on top of any cell will capture cell outputs and write to a html file which can be used to set as attachment under any defined custom facts.

  • Captured cell facts are written to temp dir {cur dir}/captured_cell_facts/Captured_Cell_Output.html

  • Each cell run output will overwrite the previous temp html file of captured cell facts. Each command output is captured as a snippet html.

  • Two args are supported with the magic command:

    • -po or --printmsgonly: print statements are only captured from any given cell

    • -cc or --capturecode: capture cell codes as well with output

  • In case of any cell mix of print messages and images or tables etc., it will capture everything except messages using print(). If you want to capture all, please use display() in place of print() method.

  • Once facts are captured, you can use `set_cell_attachment_fact()` api to attach it to any custom fact id.

set_cell_attachment_fact(self, description: str, fact_id: str) None

Set attachment fact using captured cell output. Supported for CPD version >=4.6.5.

Parameters:
  • description (str) – Description about the cell facts attachment file

  • fact_id (str) – Fact id for the attachment

A way to use me is:

>>> model.set_cell_attachment_fact(description=<file description>,fact_id=<custom fact id>)