---
sidebar:
  label: roboto.storage.download_session
  order: 3
title: roboto.storage.download_session
---
## Module Contents

### DownloadSession

```python
class roboto.storage.download_session.DownloadSession(
    items: collections.abc.Sequence[DownloadableFile],
    association: roboto.association.Association,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    caller_org_id: Optional[str] = None,
)
```

`from roboto.storage.download_session import DownloadSession`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L48-L193)

A batch of downloads of one association's files that share read-only credentials.

The SDK's own code uses it; to download files, use [`download_files()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.download_files) or [`download()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.download) instead. Roboto keeps no record of a session: its only requests fetch credentials. To download with one:

1. Build an object store from the provider `make_credential_provider` returns.
2. Inside the store's `with` block, start each file's download and pass the future the store returns to `register_download`.
3. Before that block exits, wait for the downloads with `await_downloads`, which returns the failures. Ending an iteration over the session, or leaving the session's own `with` block, also waits, and raises `ExceptionGroup` holding each failed download's exception.

**Parameters**

- **items** (`collections.abc.Sequence[DownloadableFile]`): Files to download, which iterating over the session yields.
- **association** (`roboto.association.Association`): Dataset, device, device type, or organization whose files to download. Roboto issues read-only credentials for its files.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).
- **caller_org_id** (`Optional[str]`): Organization to act in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.

#### DownloadSession.await_downloads()

```python
def await_downloads() -> list[tuple[DownloadableFile, Exception]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L160-L184)

Wait for every registered download to finish, and return the ones that failed.

Call it before the object store's `with` block exits, since the store may stop its transfers on exit. Any exception a download raised is logged and returned, not raised. The registered downloads are then forgotten, so the next call waits only for downloads registered after this one, such as retries of the failures.

**Returns**

- `list[tuple[DownloadableFile, Exception]]`: `(file, exception)` pairs for the downloads that failed; empty when every download succeeded.

#### DownloadSession.make_credential_provider()

```python
def make_credential_provider(
    bucket_name: Optional[str] = None,
) -> roboto.storage.object_store.CredentialProvider
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L112-L158)

Build a callable that fetches read-only credentials for the association's files.

Each call fetches fresh credentials from Roboto, so an object store can call it again to replace credentials that expire during a long download.

**Parameters**

- **bucket_name** (`Optional[str]`): Bucket whose credentials to fetch. `None` takes the first credentials Roboto issues.

**Returns**

- `roboto.storage.object_store.CredentialProvider`: Credential provider for an object store.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): Roboto issues no credentials for `bucket_name`. Raised when the returned function is called.

#### DownloadSession.register_download()

```python
def register_download(
    file: DownloadableFile,
    future: roboto.storage.object_store.FutureLike[None],
) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L186-L193)

Record a started download, so that the next wait for downloads includes it.

**Parameters**

- **file** (`DownloadableFile`): File the download writes.
- **future** (`roboto.storage.object_store.FutureLike[None]`): Future the object store returned when the download started.

**Returns**

- `None`

### DownloadableFile

```python
class roboto.storage.download_session.DownloadableFile
```

`from roboto.storage import DownloadableFile`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L32-L45)

Bases: `TypedDict`

A file to download: the object that holds its content and the local path to write it to.

Items of the `files` argument of [`download()`](/docs/reference/python-sdk/roboto/storage/file_service#roboto.storage.file_service.FileService.download).

**Attributes**

- **DownloadableFile.bucket_name** (`str`): Name of the bucket holding the file's object.
- **DownloadableFile.destination_path** (`pathlib.Path`): Local path to write the file's content to.
- **DownloadableFile.source_uri** (`str`): Location of the object that holds the file's content, such as `s3://<bucket>/<key>`.

### logger

```python
roboto.storage.download_session.logger
```

`from roboto.storage.download_session import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/download_session.py#L29-L29)
