---
title: csv.from() function
description: csv.from() retrieves data from a comma separated value (CSV) data source and returns a stream of tables.
url: https://docs.influxdata.com/flux/v0/stdlib/csv/from/
estimated_tokens: 1436
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/csv/from/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.14.0+

InfluxDB support

`csv.from()` retrieves data from a comma separated value (CSV) data source and
returns a stream of tables.

##### Function type signature

```js
(?csv: string, ?file: string, ?mode: string) => stream[A] where A: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### csv

CSV data.

Supports anonotated CSV or raw CSV. Use `mode` to specify the parsing mode.

### file

File path of the CSV file to query.

The path can be absolute or relative.
If relative, it is relative to the working directory of the `fluxd` process.
The CSV file must exist in the same file system running the `fluxd` process.

### mode

is the CSV parsing mode. Default is `annotations`.

**Available annotation modes**

* **annotations**: Use CSV notations to determine column data types.
* **raw**: Parse all columns as strings and use the first row as the
  header row and all subsequent rows as data.

## Examples

* [Query annotated CSV data from file](#query-annotated-csv-data-from-file)
* [Query raw data from CSV file](#query-raw-data-from-csv-file)
* [Query an annotated CSV string](#query-an-annotated-csv-string)
* [Query a raw CSV string](#query-a-raw-csv-string)

### Query annotated CSV data from file

```js
import "csv"

csv.from(file: "path/to/data-file.csv")
```

### Query raw data from CSV file

```js
import "csv"

csv.from(file: "/path/to/data-file.csv", mode: "raw")
```

### Query an annotated CSV string

```js
import "csv"

csvData =
    "
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double
#group,false,false,false,false,false,true,true,false
#default,,,,,,,,
,result,table,_start,_stop,_time,region,host,_value
,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:51:00Z,east,A,65.15
,mean,1,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
,mean,1,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:51:20Z,east,B,18.67
,mean,2,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
,mean,2,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:51:40Z,east,C,82.16
"

csv.from(csv: csvData)
```

[](#view-example-output)

View example output

#### Output data

|      \_start       |       \_stop       |       \_time       |\*region|\*host|\_value|
|--------------------|--------------------|--------------------|--------|------|-------|
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:00Z|  east  |  A   | 15.43 |
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:51:00Z|  east  |  A   | 65.15 |

|      \_start       |       \_stop       |       \_time       |\*region|\*host|\_value|
|--------------------|--------------------|--------------------|--------|------|-------|
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:20Z|  east  |  B   | 59.25 |
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:51:20Z|  east  |  B   | 18.67 |

|      \_start       |       \_stop       |       \_time       |\*region|\*host|\_value|
|--------------------|--------------------|--------------------|--------|------|-------|
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:40Z|  east  |  C   | 52.62 |
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:51:40Z|  east  |  C   | 82.16 |

### Query a raw CSV string

```js
import "csv"

csvData =
    "
_start,_stop,_time,region,host,_value
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
"

csv.from(csv: csvData, mode: "raw")
```

[](#view-example-output)

View example output

#### Output data

|      \_start       |       \_stop       |       \_time       |region|host|\_value|
|--------------------|--------------------|--------------------|------|----|-------|
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:00Z| east | A  | 15.43 |
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:20Z| east | B  | 59.25 |
|2018-05-08T20:50:00Z|2018-05-08T20:51:00Z|2018-05-08T20:50:40Z| east | C  | 52.62 |

[csv](/flux/v0/tags/csv/)[inputs](/flux/v0/tags/inputs/)
| _start | _stop | _time | *region | *host | _value |
| --- | --- | --- | --- | --- | --- |
| _start | _stop | _time | *region | *host | _value |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:00Z | east | A | 15.43 |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:51:00Z | east | A | 65.15 |

| _start | _stop | _time | *region | *host | _value |
| --- | --- | --- | --- | --- | --- |
| _start | _stop | _time | *region | *host | _value |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:20Z | east | B | 59.25 |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:51:20Z | east | B | 18.67 |

| _start | _stop | _time | *region | *host | _value |
| --- | --- | --- | --- | --- | --- |
| _start | _stop | _time | *region | *host | _value |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:40Z | east | C | 52.62 |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:51:40Z | east | C | 82.16 |

| _start | _stop | _time | region | host | _value |
| --- | --- | --- | --- | --- | --- |
| _start | _stop | _time | region | host | _value |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:00Z | east | A | 15.43 |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:20Z | east | B | 59.25 |
| 2018-05-08T20:50:00Z | 2018-05-08T20:51:00Z | 2018-05-08T20:50:40Z | east | C | 52.62 |
