# remote_file_downloader

Python API: `luxonis_ml.data.utils.remote_file_downloader`

## Classes

### RemoteFileAPIClient

#### Methods

##### download

```python
def download(url: str, destination: Path, *, timeout: float):
```

### RemoteFileDownloader

Download remote files with optional image validation.

#### Methods

##### init

```python
def __init__(api_client: RemoteFileAPIClient | None = None):
```

Create a remote file downloader.

Parameters

 * `api_client` (`RemoteFileAPIClient | None`): Optional client used for HTTP and HTTPS downloads. If omitted,
   [RequestsRemoteFileAPIClient](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/remote_file_downloader.md)
   is used.

##### download

```python
def download(url: str, destination: Path, *, timeout: float = 30.0, validate_image: bool = False) -> Path:
```

Download a file to `destination`.

Existing destination files are reused. When `validate_image` is true, both reused and newly downloaded files are checked with
Pillow and the destination suffix.

Parameters

 * `url` (`str`): Source URL. Supported schemes are `file`, `http`, `https`, `gcs`, `gs`, and `s3`.
 * `destination` (`Path`): Local destination path.
 * `timeout` (`float`): HTTP request timeout in seconds.
 * `validate_image` (`bool`): Whether to validate image content and format compatibility after download.

Returns

 * `Path`: Local destination path.

Raises

 * `ValueError`: If the URL scheme is unsupported, the destination image suffix is unsupported, the downloaded file is not a valid
   image, or the image format does not match the suffix.

#### Attributes

##### api_client

Client used for HTTP and HTTPS downloads.

### RequestsRemoteFileAPIClient

#### Methods

##### download

```python
def download(url: str, destination: Path, *, timeout: float):
```

## Functions

### download_remote_file

```python
def download_remote_file(url: str, destination: Path, *, timeout: float = 30.0, validate_image: bool = False) -> Path:
```

Download a remote file to the requested destination.

Parameters

 * `url` (`str`): Source URL.
 * `destination` (`Path`): Local destination path.
 * `timeout` (`float`): HTTP request timeout in seconds.
 * `validate_image` (`bool`): Whether to validate image content and format compatibility after download.

Returns

 * `Path`: Local destination path.

Raises

 * `ValueError`: If the URL scheme is unsupported or image validation fails.

## Attributes

### ALLOWED_IMAGE_SUFFIXES

### ALLOWED_IMAGE_SUFFIXES_BY_FORMAT

### ALLOWED_PILLOW_FORMATS_BY_FORMAT

### ALLOWED_REMOTE_URL_SCHEMES

### FS_REMOTE_URL_SCHEMES
