Skip to main content

event driven http download library with automatic resume and other features.

Project description

event driven http download library with automatic resume and other features. the goal of this module is to ease the process of downloading files and resuming interrupted downloads. the library is written in an event-driven style. the module defines the download manager class Downloader. instances of this class download a file from an http server and call callback functions whenever an event happens ralated to this download. examples of events are download state change (start, pause, complete, error) and download speed change. the following is a typical usage example:

import bitpit

url = 'https://www.python.org/static/img/python-logo.png'    #will download this
d = bitpit.Downloader(url) #downloader instance

#listen to download events and call a function whenever an event happens
#print state when state changes
d.listen('state-changed', lambda var: print('download state:', var.state))

#print speed in human readable format whenever speed changes
#speed is updated and callback is called every 1 second by default
d.listen('speed-changed', lambda var: print('download speed:', *var.human_speed))

#register another callback function to the speed change signal
#print percentage downloaded whenever speed changes
d.listen('speed-changed', lambda var: print(int(var.percentage), '%'))

#print total file size in human readable format when the downloader knows the file size
d.listen('size-changed', lambda var: print('total file size:', *var.human_size))

#done registering callbacks. lets start our download
#the following call will not block
d.start()

#do some other work...

#wait for download completion or error if you want
d.join()

this module can also be run as a main python script to download a file. you can have a look at the main function for another usage example.

commandline syntax::

python -m bitpit.py <url>

args::

url: the url to download.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitpit-0.0.3.tar.gz (9.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page