> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource.md).

# Datasource

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

A datasource is a dataset or workflow that's been added to a [workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow.md), making its tables available within that workflow. Various methods allow you to add datasources to a workflow, to change their source, version, or sample, and to remove them.

## Constructors

| Method                                                                                                                                                   | Description                                                                                                                                                               |
| -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [**`redivis.datasource`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/redivis/redivis.datasource.md)(source\[, options])         | Return a Datasource within the [default workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference.md#environment-variables), or the workflow provided. |
| [**`Workflow.datasource`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow/workflow.datasource.md)(source)                  | Return a Datasource within a specific [workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow.md).                                         |
| [**`Workflow.listDatasources`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow/workflow.listdatasources.md)(\[maxResults]) | List the Datasources of a workflow.                                                                                                                                       |

`source` is the source dataset or workflow (a [Dataset](https://docs.redivis.com/api/client-libraries/redivis-js/reference/dataset.md) or [Workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow.md) instance), or its qualified reference, e.g. `demo.iris_species`.

## Examples

```javascript
const workflow = redivis.workflow('jane.my_workflow');

// Add a dataset to the workflow
const datasource = await workflow.datasource('demo.iris_species').create();

// Switch to the dataset's sample, or pin a specific version
await datasource.update({ sample: true });
await datasource.update({ sample: false, version: 'v1_0' });

// Replace the source with a different dataset, mapping tables that were renamed
await datasource.update({
  sourceDataset: 'demo.iris_species_v2',
  mappedTables: [['iris', 'iris_flowers']],
});

const dataset = await datasource.sourceDataset(); // -> Returns a Dataset

// Remove the datasource, along with the transforms and notebooks that depend on it
await datasource.delete();
```

## Attributes

| Name                  | Description                                                                                                                                                                                                                             |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`workflow`**        | The [Workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow.md) that the datasource belongs to.                                                                                                          |
| **`sourceReference`** | The qualified reference of the datasource's source dataset or workflow.                                                                                                                                                                 |
| **`properties`**      | An object containing the [API resource representation of the datasource](https://docs.redivis.com/api/resource-definitions/datasource.md). This will only be populated after certain methods are called, particularly the `get` method. |

## Methods

| Method                                                                                                                                          | Description                                                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| [**`Datasource.create`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.create.md)()                 | Add the source to the workflow.                                                                               |
| [**`Datasource.delete`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.delete.md)()                 | Remove the datasource from the workflow, along with the transforms and notebooks that depend on it.           |
| [**`Datasource.exists`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.exists.md)()                 | Check whether the datasource exists.                                                                          |
| [**`Datasource.get`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.get.md)()                       | Fetch the datasource's metadata, populating `datasource.properties`.                                          |
| [**`Datasource.sourceDataset`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.sourcedataset.md)()   | Return the source [Dataset](https://docs.redivis.com/api/client-libraries/redivis-js/reference/dataset.md).   |
| [**`Datasource.sourceWorkflow`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.sourceworkflow.md)() | Return the source [Workflow](https://docs.redivis.com/api/client-libraries/redivis-js/reference/workflow.md). |
| [**`Datasource.update`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource/datasource.update.md)(options)          | Change the datasource's source, version, sample, or table mappings.                                           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redivis.com/api/client-libraries/redivis-js/reference/datasource.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
