# Notebook

## *class* <mark style="color:purple;">Notebook</mark>

An interface for working with notebooks on Redivis.

## Constructors

<table data-header-hidden><thead><tr><th width="368">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="redivis/redivis.current_notebook"><strong><code>redivis.current_notebook</code></strong></a>()</td><td>Get a reference to the current notebook. Can only be called from within a running Redivis notebook.</td></tr><tr><td><a href="redivis/redivis.notebook"><strong><code>redivis.notebook</code></strong></a>(name)</td><td>Create a reference to a notebook based on its (qualified) name</td></tr><tr><td><a href="workflow/workflow.notebook"><strong><code>Workflow.notebook</code></strong></a>()</td><td>Return a notebook within a specific <a href="workflow">workflow</a>. </td></tr><tr><td><a href="workflow/workflow.list_notebooks"><strong><code>Workflow.list_notebooks</code></strong></a>()</td><td>Returns a list of Notebooks within a workflow</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Run a notebook" %}

<pre><code><strong>username = "imathews"
</strong>workflow_name = "example_workflow_climate_analysis:x7kh"
notebook_name = "visualize_precipitation_trends:2f2v"

notebook = redivis.notebook(f"{username}.{workflow_name}.{notebook_name}")
notebook.run()
</code></pre>

{% endtab %}

{% tab title="Create a notebook output table" %}

```python
df = get_dataframe_somehow()

notebook = redivis.current_notebook()

# Create an output table on the current notebook
# Optional parameter, append (default False), determines whether the output appends to
#  or replaces the output table.
notebook.create_output_table(df, append=False) 

# Can also pass a path to a parquet file or csv
notebook.create_output_table("path/to/file.parquet")
```

{% endtab %}
{% endtabs %}

## Attributes

<table data-header-hidden><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>workflow</code></strong></td><td>A reference to the <a href="workflow">Workflow</a> instance that is associated with this notebook.</td></tr><tr><td><strong><code>properties</code></strong></td><td>A dict containing the <a href="../../../resource-definitions/notebook">API resource representation of the notebook</a>. This will only be populated after certain methods are called, particularly the <code>get</code> method, and will otherwise be <code>None</code>.</td></tr><tr><td><strong><code>qualified_reference</code></strong></td><td><p></p><p>The <a href="../../../referencing-resources">fully qualified reference</a> to this notebook</p><p>For example,</p><pre class="language-http"><code class="lang-http">imathews.example_workflow_climate_analysis:x7kh.visualize_precipitation_trends:2f2v
</code></pre></td></tr><tr><td><strong><code>scoped_reference</code></strong></td><td>The canonical reference for the notebook, without any qualifiers. E.g., <code>visualize_precipitation_trends:2f2v</code></td></tr></tbody></table>

## Methods

<table data-header-hidden><thead><tr><th width="368">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="notebook/notebook.create_output_table"><strong><code>notebook.create_output_table</code></strong></a>(data[, ...])</td><td>Create or append to an output table, using data from within the (running) notebook.</td></tr><tr><td><a href="notebook/notebook.get"><strong><code>notebook.get</code></strong></a>()</td><td>Fetches the notebook, after which notebook.properties will contain a dict with entries corresponding to the properties on the <a href="../../../resource-definitions/notebook">notebook resource definition</a>. Will raise an error if the notebook does not exist.</td></tr><tr><td><a href="notebook/notebook.exists"><strong><code>notebook.exists</code></strong></a>()</td><td>Check whether the notebook exists.</td></tr><tr><td><a href="notebook/notebook.output_table"><strong><code>notebook.output_table</code></strong></a>()</td><td>Get a reference to the notebook's output table, if it exists.</td></tr><tr><td><a href="notebook/notebook.run"><strong><code>notebook.run</code></strong></a>([*, wait_for_finish=True])</td><td>Run a notebook.</td></tr><tr><td><a href="notebook/notebook.referenced_tables"><strong><code>notebook.referenced_tables</code></strong></a>()</td><td>Get an ordered list of tables referenced by the notebook.</td></tr><tr><td><a href="notebook/notebook.referenced_tables"><strong><code>notebook.source_table</code></strong></a>()</td><td>Get the notebook's source table.</td></tr><tr><td><a href="notebook/notebook.stop"><strong><code>notebook.stop</code></strong></a>()</td><td>Stop a running notebook.</td></tr><tr><td><a href="notebook/notebook.update"><strong><code>notebook.update</code></strong></a>([*, name, source_table])</td><td>Update the notebook's name and/or source.</td></tr></tbody></table>
