# Workflow

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

Workflows on Redivis are where analytical pipelines are built and executed. All workflows are owned by a user, and are made up of datasources, transforms, notebooks, and tables.

{% hint style="warning" %}
Workflows were previously referred to as "Projects" on Redivis. Existing code that utilized the "project" terminology will continue to work (e.g., `User.list_projects()`).&#x20;

However, we encourage users to migrate their code to prevent future issues and confusion.
{% endhint %}

## Constructors

<table><thead><tr><th width="367">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="redivis/redivis.current_workflow"><strong><code>redivis.current_workflow</code></strong></a>()</td><td>Get the current default workflow. Typically called within notebooks.</td></tr><tr><td><a href="user/user.workflow"><strong><code>Organization.list_workflows</code></strong></a>([max_results])</td><td>List all workflows owned by an organization.</td></tr><tr><td><a href="user/user.workflow"><strong><code>Organization.workflow</code></strong></a>(name)</td><td>Construct a new workflow instance that references a workflow owned by an organization.</td></tr><tr><td><a href="user/user.workflow"><strong><code>User.list_workflows</code></strong></a>([max_results])</td><td>List all workflows owned by a user.</td></tr><tr><td><a href="user/user.workflow"><strong><code>User.workflow</code></strong></a>(name)</td><td>Construct a new workflow instance that references a workflow owned by a user.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

<pre class="language-python"><code class="lang-python">workflow = redivis.user("imathews").workflow("example_workflow_climate_analysis")
tables = workflow.list_tables()

for table in tables:
<strong>    # Properties will be populated with the table.list resource representation
</strong>    print(table.properties) 
    
    table.get()
    # Properties will now be populated with the table.get resource representation
    print(table.properties) 

workflow.table("join_lat_lon_output").exists() # -> TRUE
</code></pre>

{% endtab %}

{% tab title="Scoped queries" %}

```python
workflow = redivis.user("imathews").workflow("example_workflow_climate_analysis")

query = workflow.query("""
    SELECT
        id,
        EXTRACT(YEAR FROM date) AS year,
        SUM(value) AS annual_precip
    FROM daily_observations
    WHERE (element = 'PRCP')
    GROUP BY id, year
""")

query.to_pandas_dataframe()
# 	id	        year	    annual_precip
# 0	CA0023026HN	2003	    2925.0
# ...
```

{% endtab %}
{% endtabs %}

## Attributes

| **`properties`**          | <p>A dict containing the <a href="../../../resource-definitions/workflow">API resource representation of the workflow</a>. <br><br>This will be fully populated after calling <a href="workflow/workflow.get">Workflow\.get()</a>, and partially populated for workflows created via <a href="user/user.list_workflows">User.list\_workflows</a>. Otherwise will be <code>None</code>.</p> |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`qualified_reference`** | The [fully qualified reference](https://docs.redivis.com/api/referencing-resources) for the workflow, which can be used in SQL queries or the REST API. E.g., `imathews.example_`workflow`_climate_analysis:x7kh`                                                                                                                                                                          |
| **`scoped_reference`**    | The canonical reference for the workflow, without the username qualifier. E.g.,: `example_`workflow`_climate_analysis:x7kh`                                                                                                                                                                                                                                                                |
| **`user`**                | A reference to the [User](https://docs.redivis.com/api/client-libraries/redivis-python/reference/user) instance that constructed this workflow.                                                                                                                                                                                                                                            |
| **`organization`**        | A reference to the [Organization](https://docs.redivis.com/api/client-libraries/redivis-python/reference/organization) instance that constructed this workflow.                                                                                                                                                                                                                            |

## Methods

<table data-header-hidden><thead><tr><th width="441"></th><th></th></tr></thead><tbody><tr><td><a href="workflow/workflow.datasource"><strong><code>Workflow.datasource</code></strong></a>()</td><td>Create a reference to a datasource within the workflow.</td></tr><tr><td><a href="workflow/workflow.exists"><strong><code>Workflow.exists</code></strong></a>()</td><td>Check whether the workflow exists.</td></tr><tr><td><a href="workflow/workflow.get"><strong><code>Workflow.get</code></strong></a>()</td><td>Get the workflow, populating the <code>properties</code> attribute on the current instance.</td></tr><tr><td><a href="workflow/workflow.list_datasources"><strong><code>Workflow.list_datasources</code></strong></a>([max_results])</td><td>List all datasources in the workflow.</td></tr><tr><td><a href="workflow/workflow.list_notebooks"><strong><code>Workflow.list_notebooks</code></strong></a>([max_results])</td><td>List all notebooks in the workflow.</td></tr><tr><td><a href="workflow/workflow.list_parameters"><strong><code>Workflow.list_parameters</code></strong></a>([max_results])</td><td>List all parameters in the workflow</td></tr><tr><td><a href="workflow/workflow.list_tables"><strong><code>Workflow.list_tables</code></strong></a>([max_results])</td><td>List all tables in the workflow.</td></tr><tr><td><a href="workflow/workflow.list_transforms"><strong><code>Workflow.list_transforms</code></strong></a>([max_results])</td><td>List all transforms in the workflow.</td></tr><tr><td><a href="workflow/workflow.notebook"><strong><code>Workflow.notebook</code></strong></a>(name)</td><td>Create a reference to a specific notebook within the workflow.</td></tr><tr><td><a href="workflow/workflow.parameter"><strong><code>Workflow.parameter</code></strong></a>(name)</td><td>Create a reference to a specific parameter within the workflow.</td></tr><tr><td><a href="workflow/workflow.query"><strong><code>Workflow.query</code></strong></a>(query_string)</td><td>Create a query scoped to the workflow.</td></tr><tr><td><a href="workflow/workflow.table"><strong><code>Workflow.table</code></strong></a>(name)</td><td>Create a reference to a specific table within the workflow.</td></tr><tr><td><a href="workflow/worfklow.transform"><strong><code>Workflow.transform</code></strong></a>(name)</td><td>Create a reference to a specific transform within the workflow.</td></tr><tr><td><a href="workflow/workflow.update_variables"><strong><code>Workflow.update_variables</code></strong></a>(variables)</td><td>Batch update variable metadata across tables in a workflow.</td></tr></tbody></table>
