Available languages: [Python](https://databento.com/docs/api-historical/helpers/dbn-store-to-csv.python.md) · [C++](https://databento.com/docs/api-historical/helpers/dbn-store-to-csv.cpp.md) · [Rust](https://databento.com/docs/api-historical/helpers/dbn-store-to-csv.rust.md) · [HTTP](https://databento.com/docs/api-historical/helpers/dbn-store-to-csv.http.md)

Source: https://databento.com/docs/api-historical/helpers/dbn-store-to-csv


### DBNStore.to_csv

Write data to a file in CSV format.

#### API method

```python
DBNStore.to_csv(
    path: PathLike[str] | str,
    pretty_ts: bool = True,
    pretty_px: bool = True,
    map_symbols: bool = True,
    compression: Compression | str = Compression.NONE,
    schema: Schema | str | None = None,
    mode: Literal["w", "x"] = "w",
) -> None
```

#### Parameters

| Parameter | Type | Required | Description |
| `path` | PathLike[str] or str | required | The file path to write to. |
| `pretty_ts` | bool, default True | optional | Whether timestamp columns are converted to tz-aware `pandas.Timestamp` (UTC). |
| `pretty_px` | bool, default True | optional | Whether price columns are correctly scaled as display prices. |
| `map_symbols` | bool, default True | optional | If symbology mappings from the metadata should be used to create a 'symbol' column, mapping the instrument ID to its native symbol for every record. |
| `compression` | Compression or str | optional | The output compression for writing. Must be either 'zstd' or 'none'. |
| `schema` | Schema or str | optional | The data record [schema](https://databento.com/docs/schemas/whats-a-schema.md) for the output CSV. Must be one of the values from [list_schemas](https://databento.com/docs/api-historical/metadata/metadata-list-schemas.md). This is only required when reading a `DBNStore` with mixed record types. |
| `mode` | str | optional | The file write mode to use, either "x" or "w". Defaults to "w". |

#### Returns

`None`

#### Example usage

```python
import databento as db

client = db.Historical("$YOUR_API_KEY")

data = client.timeseries.get_range(
    dataset="GLBX.MDP3",
    symbols=["ESM2"],
    schema="trades",
    start="2022-06-06",
)

# Save streamed data to .csv
data.to_csv("GLBX-ESM2-20220606-trades.csv")
```
