import requests
from pathlib import Path
import tempfile
import shutil


def download_file(url: str) -> str:
    """
    Download ngrok binary file to local

    Args:
        url (:code:`str`):
            URL to download

    Returns:
        :code:`download_path`: str
    """
    local_filename = url.split("/")[-1]
    r = requests.get(url, stream=True)
    download_path = str(Path(tempfile.gettempdir(), local_filename))
    with open(download_path, "wb") as f:
        shutil.copyfileobj(r.raw, f)
    return download_path