# Datasource

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

An interface for working with workflow datasources 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/redivisusddatasource"><strong><code>redivis$datasource</code></strong></a>(name)</td><td>Create a reference to a datasource. Can only be called if a default workflow is set.</td></tr><tr><td><a href="workflow/workflowusddatasource"><strong><code>Workflow$datasource</code></strong></a>(name)</td><td>Create a reference to a Datasource within a specific <a href="workflow">workflow</a>. </td></tr><tr><td><a href="workflow/workflowusdlist_datasources"><strong><code>Workflow$list_datasources</code></strong></a>([max_results])</td><td>Returns a list of Datasources within a workflow</td></tr></tbody></table>

## Examples

```r
username <- "imathews"
workflow_name <- "example_workflow_climate_analysis:x7kh"
dataset_name <- "ghcn_daily_weather_data"

workflow <- redivis$workflow(f"{username}.{workflow_name}")
datasource <- workflow$datasource(dataset_name)

datasource$update(version="v2.0")
```

## Attributes

| **`workflow`**   | A reference to the [Workflow](https://docs.redivis.com/api/client-libraries/redivis-r/reference/workflow) instance that this datasource belongs to.                                                                                                                   |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`properties`** | A named list containing the [API resource representation of the datasource](https://docs.redivis.com/api/resource-definitions/datasource). This will only be populated after certain methods are called, particularly the `get` method, and will otherwise be `None`. |

## Methods

<table data-header-hidden><thead><tr><th width="368">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="datasource/datasourceusdcreate"><strong><code>datasource$create</code></strong></a>()</td><td>Create a new datasource in a workflow</td></tr><tr><td><a href="datasource/datasourceusdget"><strong><code>datasource$get</code></strong></a>()</td><td>Fetches the datasource, after which datasource.properties will contain a dict with entries corresponding to the properties on the <a href="../../../resource-definitions/datasource">datasource resource definition</a>. Will raise an error if the datasource does not exist.</td></tr><tr><td><a href="datasource/datasourceusdexists"><strong><code>datasource$exists</code></strong></a>()</td><td>Check whether the datasource exists.</td></tr><tr><td><a href="datasource/datasourceusdsource_dataset"><strong><code>datasource$source_dataset</code></strong></a>()</td><td>Returns a reference to this datasource's source dataset.</td></tr><tr><td><a href="datasource/datasourceusdsource_workflow"><strong><code>datasource$source_workflow</code></strong></a>()</td><td>Returns a reference to this datasource's source workflow.</td></tr><tr><td><a href="datasource/datasourceusdupdate"><strong><code>datasource$update</code></strong></a>([*, ...])</td><td>Update the datasource to reference a new dataset, workflow, or version thereof.</td></tr></tbody></table>
