Why PostgreSQL execution time is fast but respond is slow?
I recommend you to test the performance inside the code. This way you could measure the time it takes it line of your code and decide if this is because your environment ( for example the building time of your script) or it is taking more time due to the response from the server side.
To to that you can use the time Python library. An example on how to do this could be:
import time
start_time = time.time()
#
# Your code stuff
#
elapsed_time = time.time() - start_time
print('It took {} seconds to run your code'.format(elapsed_time))