Limit download (or upload) rate in PyCurl
I'm used to work with curl in other programming languages like php or perl, so pycurl became my first choice in python url access libraries .
Pycurl it's not a native module like urllib2, instead is a wrapper for the C library libcurl, it is not as fancy as native python modules are, but is extremely fast and you have lots of features. Also if you want to find documentation about how to use Pycurl is better to look at libcurl's documentation and examples.
And so I did. In libcurl documentation I found which options i could set for libcurl API to limit download bandwidth usage, MAX_RECV_SPEED_LARGE. Note that options in Pycurl are the same that in libcurl without the prefix CURLOPT.
Here is a simple example of how to limit download a file with a 10KB limit rate:
-
import pycurl
-
-
c = pycurl.Curl()
-
c.setopt(c.URL, "http://python.org/ftp/python/2.5.2/Python-2.5.2.tgz")
-
c.setopt(c.MAX_RECV_SPEED_LARGE, 10000)
-
c.setopt(c.WRITEDATA, file("python-2.5.2.tar.gz","w"))
-
c.perform()
And this is my story

on Mayo 8th, 2008 at 10:28 am
Limit download (or upload) rate in PyCurl…
Uso de pycurl para limitar la velocidad de descarga o subida mediante la librería libcurl….