Package: fastdl
fastdlDownload and extract files fast and easily.file_path=fastdl.download(url,extract=True,dir_prefix="downloads")FeaturesParallel downloads (threads and processes)Cache for downloads and extractionsEasy extractionsProgress barsEasily configurableInstallation$pipinstallfastdlUsagefastdlcan be be used in two different ways, download a single file or download multiple files in parallel:Single filefile_path=fastdl.download(url,dir_prefix="downloads",extract=True)Multiple fileswithfastdl.Parallel(prefer="threads"):downloads=[]forurlinurls:download=p.download(url,dir_prefix="downloads")# same argumentsfordownloadindownloads:file_path=download.get()# block until download is finishedParametersParameterDescriptionTypeDefaulturlUrl to downloadstrfnameFile name of download file. Can be an absolute path. Can receive a function withresponseas an argumentstr or callableNonedir_prefixDirectory to store download file. Used only iffnameis not an absolute path. Defaults to current directory or value specified byfastdl.conf["default_dir_prefix"]strNonesubdir_prefixSubdirectory insidedir_prefixto store download. Defaults to no subdirectory.str""headersDictionnary of HTTP headers to send. For example:{"User-Agent": "fastdl/0.1"}dict{}content_dispositionUsed only iffnameis None. IfTrue, try to infer the filename from content disposition. IfFalse, url will be used to infer filename.boolFalseblocksizeNumber of bytes to read and write for each iterationint8192file_hashFile hash. If the file hash doesn't match, it will be re-downloaded.strNonehash_algorithmHash algorithm. One of the following:"sha256","sha512","sha1","md5"orauto. By default, it will try to infer the algorithm according to the length of thefile_hashstrautoextractWhether or not extract fileboolFalseextract_dirDirectory to store extracted files. By default same directory as the filestrNoneprogressbarWhether or not show a progress barboolTrueforce_downloadWhether or not force download if file already exists. By default, it doesn't re-download file unless file hash doesn't matchboolFalseforce_extractionWhether or not force extraction if file already existsboolFalseExamplesDownload file and re-download if hash doesn't matchimportfastdlfile_hash="155fdb3732e82cc4864c441e6400def0"url="https://file-examples.com/wp-content/uploads/2017/02/zip_2MB.zip"file_path=fastdl.download(url,extract=True,dir_prefix="downloads",file_hash=file_hash)Download multiple files in parallelimportfastdlurls=["https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4","https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_640_3MG.mp4","https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1280_10MG.mp4"]withfastdl.Parallel(prefer="processes",max_workers=2)asp:downloads=[]forurlinurls:download=p.download(url,dir_prefix="downloads")fordownloadindownloads:file_path=download.get(timeout=10)# wait 10 seconds or raise timeout if download hasn't finishedDownload from a list of urls in parallelimportfastdlfromfastdl.utilsimportlineswithfastdl.Parallel()asp:downloads=[]forurlinlines("urls.txt"):download=p.download(url)downloads.append(download)fordownloadindownloads:file_path=download.get()Change default download directoryIf you're using a directory for all your downloads (e.g ~/.myapp), you can easily change the default directory for your downloads:# myapp/__init__.pyimportfastdlfastdl.conf["default_dir_prefix"]="~/.myapp"# myapp/file.pyfile_path=fastdl.download("https://file-examples.com/wp-content/uploads/2017/02/zip_2MB.zip")file_path=="~/.myapp/zip_2MB.zip"Checkexamplesfolder to see examples in action.