跳转到主要内容

一个HTTP和FTP并行文件下载器。

项目描述

Latest PyPI version

使用asyncio的并行文件下载器。parfive可以并行处理多个文件的下载,也可以将每个文件分成多个块进行下载。

用法

asciicast demo of parfive

parfive通过创建下载器对象、向其中添加文件然后运行下载来工作。parfive提供了一个同步API,但使用asyncio并行化文件下载。

一个简单的示例是

from parfive import Downloader
dl = Downloader()
dl.enqueue_file("http://data.sunpy.org/sample-data/predicted-sunspot-radio-flux.txt", path="./")
files = dl.download()

Parfive还包含一个CLI。以下示例将同时下载两个文件。

$ parfive 'http://212.183.159.230/5MB.zip' 'http://212.183.159.230/10MB.zip'
$ parfive --help
usage: parfive [-h] [--max-conn MAX_CONN] [--overwrite] [--no-file-progress]
              [--directory DIRECTORY] [--print-filenames]
              URLS [URLS ...]

Parfive, the python asyncio based downloader

positional arguments:
  URLS                  URLs of files to be downloaded.

optional arguments:
  -h, --help            show this help message and exit
  --max-conn MAX_CONN   Number of maximum connections.
  --overwrite           Overwrite if the file exists.
  --no-file-progress    Show progress bar for each file.
  --directory DIRECTORY
                        Directory to which downloaded files are saved.
  --print-filenames     Print successfully downloaded files's names to stdout.

结果

parfive.Downloader.download返回一个parfive.Results对象,它是一个已下载文件名的列表。它还跟踪任何下载失败的文件。

错误处理

如果文件下载失败,则URL和来自服务器的响应将存储在parfive.Downloader返回的Results对象中。这些可以用来通知用户错误。(注意,如果下载失败,进度条将以不完整的状态结束,即它会显示4/5 Files Downloaded)。

Results对象是一个具有额外属性errors的列表,这个属性返回一个包含命名元组的列表,其中这些命名元组包含.url.response,这是一个aiohttp.ClientResponseaiohttp.ClientError对象。

安装

parfive可在PyPI上使用,您可以使用pip安装它

pip install parfive

或者如果您想使用FTP下载

pip install parfive[ftp]

需求

  • Python 3.7或更高版本

  • aiohttp

  • tqdm

  • aioftp (用于FTP下载)

许可证

MIT 许可

作者

parfiveStuart Mumford 编写。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

parfive-2.1.0.tar.gz (34.0 kB 查看哈希值)

上传时间 源代码

构建分发

parfive-2.1.0-py3-none-any.whl (27.6 kB 查看哈希值)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面