Available languages: [Python](https://databento.com/docs/api-historical/batch/batch-download-async.python.md) · [C++](https://databento.com/docs/api-historical/batch/batch-download-async.cpp.md) · [Rust](https://databento.com/docs/api-historical/batch/batch-download-async.rust.md) · [HTTP](https://databento.com/docs/api-historical/batch/batch-download-async.http.md)

Source: https://databento.com/docs/api-historical/batch/batch-download-async



### Historical.batch.download_async

Asynchronously download a batch job or a specific file to `{output_dir}/{job_id}/`.

Will automatically generate any necessary directories if they do not already exist.

Related: [Download center]($PLATFORM_HOSTNAME/portal/download-center).

#### API method

```python
Historical.batch.download_async(
    job_id: str,
    output_dir: PathLike[str] | str | None = None,
    filename_to_download: str | None = None,
    keep_zip: bool = False,
) -> Awaitable[list[Path]]
```

> **Info**
>
> This method is a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutines) and must be used with an [await](https://docs.python.org/3/reference/expressions.html#await) expression.

#### Parameters

| Parameter | Type | Required | Description |
| `job_id` | str | required | The batch job identifier. |
| `output_dir` | PathLike[str] or str | optional | The directory to download the file(s) to. If `None`, defaults to the current working directory. |
| `filename_to_download` | str | optional | The specific file to download. If `None` then will download all files for the batch job. |
| `keep_zip` | bool, default False | optional | If `True`, and `filename_to_download` is `None`, all job files will be saved as a .zip archive in the `output_dir`. |

#### Returns

`list[Path]`

A list of paths to the downloaded files.

#### Example usage

```python
import asyncio
import databento as db

client = db.Historical("$YOUR_API_KEY")

# Download all files for the batch job
coro = client.batch.download_async(
    job_id="GLBX-20220610-5DEFXVTMSM",
    output_dir="my_data/",
)
asyncio.run(coro)

# Alternatively, you can download a specific file
coro = client.batch.download_async(
    job_id="GLBX-20220610-5DEFXVTMSM",
    output_dir="my_data/",
    filename_to_download="metadata.json",
)
asyncio.run(coro)
```
