Skip to content

download

download

download(url: str, output_path: Path, timeout: int = 30)

Download a file from a given URL and save it to the specified output path.

Parameters:

Name Type Description Default
url str

The URL to download from

required
output_path Path

The path to save the downloaded file to

required
timeout int

The timeout for the request

30
Source code in src/torah_dl/core/download.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def download(url: str, output_path: Path, timeout: int = 30):
    """Download a file from a given URL and save it to the specified output path.

    Args:
        url: The URL to download from
        output_path: The path to save the downloaded file to
        timeout: The timeout for the request
    """
    try:
        response = requests.get(url, timeout=timeout)
        response.raise_for_status()

    except requests.RequestException as e:
        raise DownloadError(url) from e

    with open(output_path, "wb") as f:
        f.write(response.content)