arde en el infierno

Abril 22nd, 2008

Limit download (or upload) rate in PyCurl

Posted by arcturus in Tecnología

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:

PYTHON:
  1. import pycurl
  2.  
  3. c = pycurl.Curl()
  4. c.setopt(c.URL, "http://python.org/ftp/python/2.5.2/Python-2.5.2.tgz")
  5. c.setopt(c.MAX_RECV_SPEED_LARGE, 10000)
  6. c.setopt(c.WRITEDATA, file("python-2.5.2.tar.gz","w"))
  7. c.perform()

And this is my story :P

One Response to ' Limit download (or upload) rate in PyCurl '

Subscribe to comments with RSS or TrackBack to ' Limit download (or upload) rate in PyCurl '.


  1. 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….

Leave a reply


*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation