download.py 607 B

12345678910111213141516171819
  1. from pathlib import Path
  2. from typing import Optional, Union
  3. from .. import context, core, helpers
  4. def download(src: Union[str, Path], filename: Optional[str] = None) -> None:
  5. """Download
  6. Function to trigger the download of a file.
  7. :param src: target URL or local path of the file which should be downloaded
  8. :param filename: name of the file to download (default: name of the file on the server)
  9. """
  10. if helpers.is_file(src):
  11. src = core.app.add_static_file(local_file=src, single_use=True)
  12. else:
  13. src = str(src)
  14. context.get_client().download(src, filename)