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

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


### DBNStore.to_file

Write data to a DBN file.

#### API method

```python
DBNStore.to_file(
    path: PathLike[str] | str,
    mode: Literal["w", "x"] = "w",
    compression: Compression | str | None = None,
) -> None
```

#### Parameters

| Parameter | Type | Required | Description |
| `path` | PathLike[str] or str | required | The file path to write to. |
| `mode` | str | optional | The file write mode to use, either "x" or "w". Defaults to "w". |
| `compression` | Compression or str | optional | The compression format to write. If `None`, uses the same compression as the underlying data. |

#### Returns

A [DBNStore](https://databento.com/docs/api-historical/helpers/dbn-store.md) object.

#### 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 .dbn.zst
data.to_file("GLBX-ESM2-20220606.trades.dbn.zst")
```
