# Export data

> Download channel data from a range or a line plot as a CSV file, or export it in code.

The Console exports channel data as a CSV file. You can export the data of a [range](https://docs.synnaxlabs.com/reference/ranges), of a [line plot](https://docs.synnaxlabs.com/reference/visualize/line-plots), or of a region that you select on a line plot. Each way opens the same download dialog.

## Export a range

1. Open the [range overview](https://docs.synnaxlabs.com/reference/ranges/find#range-overview).
2. Click (**Download data for** followed by the range name **as CSV**) at the top of the overview.
3. In the dialog, select the channels to export.
4. Click **Download**, then choose where to save the file.

The dialog uses the start and end of the range. It has no channels selected, because a range does not hold a list of channels.

## Export from a line plot

When you export from a line plot, the dialog selects the channels of the plot for you.

### Whole line plot

Open the component toolbar of the line plot and click . The dialog selects the X and Y channels of the plot. Its time span covers all the ranges on the plot, and a live window ends at the current time.

### Selected region

1. [Select a region](https://docs.synnaxlabs.com/reference/visualize/line-plots#select-a-region) of the line plot.
2. Right-click the selection and select **Download region as CSV**.

The dialog uses the start and end of the selection.

### Range bar

Right-click a range bar on the line plot and select **Download as CSV**. The dialog uses the start and end of that range.

## Download dialog

The download dialog has these fields:

* **From** and **To**: The start and end of the data to export. Change them to export a shorter or longer period.
* **Channels**: The channels to export. Virtual channels are not in the list.
* **Downsample factor**: Keeps one sample of every N samples. It is a whole number, 1 or more. The default is 1, which keeps all samples.

**Download** is disabled until you select at least one channel. The end time cannot be before the start time. Press **Ctrl+Enter** (**Cmd+Enter** on macOS) to download.

## CSV format

* The first line is a header with the name of each channel.
* Synnax adds the index channel of each channel that you select. Index channels hold the timestamps.
* Timestamps are integers in nanoseconds since the Unix epoch (UTC).
* Each line holds the samples that share one timestamp. Lines are in time order.
* Channels with different index channels have different timestamp columns. A cell is empty when a channel has no sample at the timestamp of that line.

## Export data in code

A script exports data on a schedule, or as the last step of a test. The Core writes the file, so the script never holds the whole export in memory.

**Python**

```python
rng = client.ranges.retrieve(name="Oct 10 Burst Test")
client.read_csv(rng.time_range, ["tank_pressure", "tank_temperature"], dest="test.csv")
```

**TypeScript**

```typescript
import { createWriteStream } from "node:fs";
import { Writable } from "node:stream";

const rng = await client.ranges.retrieve("Oct 10 Burst Test");
const csv = await client.readCSV(rng.timeRange, ["tank_pressure", "tank_temperature"]);
await csv.pipeTo(Writable.toWeb(createWriteStream("test.csv")));
```

The file has the same format as a Console export. The clients can also write an NI TDMS file. See [export to CSV](https://docs.synnaxlabs.com/reference/client/read-data#export-to-csv) and [export to TDMS](https://docs.synnaxlabs.com/reference/client/read-data#export-to-tdms), which use the Python or TypeScript client.
