Yes, the Python requests
lib perform a DNS query at every request;
However, you can improve that behavior using requests-cache.
requests-cache is a persistent HTTP cache that provides an easy way to get better performance with the python requests library.
It's really easy to use, 1 minute, 2 lines of code and you're ready to go.
import requests
import requests_cache
requests_cache.install_cache('my_simple_cache')
Your subsequent python requests
calls should automagically use the cache now. And there are more fine-grained options available if you want, like customizing expire time, etc.
(This solved a problem I was having trying to batch process something that suddenly stopped working after 10K calls, not because the service was unavailable, but because the DNS requests would get refused at my intranet DNS server.)
socket.getaddrinfo
which should be using thegetaddrinfo
of the OS you are using according to this answer on another SO question. So it should cache the results depending on the OS for each subsequent request to the same hostname. – Wreckfish