This python script is communicating with the bitcoin program (the one available from the bitcoin website which is running in headless mode) via JSON-RPC. It's asking the program which is communicating with all the other nodes for work, performing that work and returning an answer eventually to the bitcoin program which then will propagate it to other nodes. This python script is simply performing the work in python instead of (in parallel?) the bitcoin headless server performing the work.
Essentially, attempting to implement the communication protocol of bitcoin, it's piggy backing off the bitcoin application and just attempting to perform the work. If you've ever looked at the "specification" of the communication protocol you can certainly emphasise going with this route.