If you can generate a list of arguments as strings, you can use the subprocess module easily. For example:
def curl_delete(url):
cmd = ['curl', '-XDELETE', url]
subprocess.check_call(cmd)
If you want to use the retcode as a value instead of just raising on non-zero:
return subprocess.call(cmd)
Or if you want to get the stdout as a value, or anything else... See the subprocess docs section on replacing shell commands. Usually what you want is something like:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out, _ = p.communicate()
return out
However, it's worth noting that the urllib2 module can do everything in your examples (although it will be painful for some of them), and httplib can do almost anything curl can do. For example:
def http_delete(url):
bits = urlparse.urlparse(bits)
conn = httplib.HTTPConnection(bits.host, bits.port)
req = conn.request('delete', url)
return req.getresponse()
This will return an object that can give you the response code and message, headers, and body. See the examples for more details.