title: How to reliably check if a domain has been registered or is available?
body: <h2>Objective</h2>
  
  <p>I need a <strong>reliable</strong> way to check in Python if a domain of <strong>any TLD</strong> has been registered or is available. The bold phrases are the key points that I'm struggling with.</p>
  
  <h2>What I tried?</h2>
  
  <ol>
  <li><strong>WHOIS</strong> is the obvious way to do the check and an existing Python library like the popular <strong><a href="https://pypi.python.org/pypi/python-whois" rel="noreferrer">python-whois</a></strong> was my first try. The problem is that it doesn't seem to be able to retrieve information for some of the TLDs, e.g. <em>.run</em>, while it works mostly fine for older ones, e.g. <em>.com</em>.</li>
  <li>So if python-whois is not reliable, maybe just a <strong>wrapper for the Linux's whois</strong> would be better. I tried <strong><a href="https://pypi.python.org/pypi/whois/0.7" rel="noreferrer">whois library</a></strong> and unfortunately it supports only a limited set of TLDs, apparently to make sure it can always parse the results.</li>
  <li><p>As I don't really need to parse the results, I ripped the code out of the whois library and tried to do the query by <strong>calling Linux's whois</strong> myself:</p>
  
  <pre><code>p = subprocess.Popen(['whois', 'example.com'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  r = p.communicate()[0]
  print(r.decode())
  </code></pre>
  
  <p>That works much better. Except <strong>it's not that reliable either</strong>. I tried one particular domain and got <em>"Your connection limit exceeded. Please slow down and try again later."</em> Well, it's not me who is exceeding the limit. Being behind a single IP in a huge office means that somebody else might hit the limit before I make a query.</p></li>
  <li>Another thought was <strong>not to use WHOIS</strong> and instead do a DNS lookup. However, I need to deal with domains that are registered or in the protected phase after expiry and don't have DNS records so this is apparently not possible.</li>
  <li>Last idea was to do the queries via an <strong>API of some 3rd party service</strong>. The problem is trust in those services as they might <a href="https://en.wikipedia.org/wiki/Domain_name_front_running" rel="noreferrer">snatch</a> an available domain that I check.</li>
  </ol>
  
  <h2>Similar questions</h2>
  
  <p>There are already similar questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11584942/a-stable-way-to-check-domain-availability-with-pywhois">a stable way to check domain availability with pywhois</a></li>
  <li><a href="https://stackoverflow.com/questions/47418061/testing-domain-name-availability-with-pythonwhois">Testing domain-name availability with pythonwhois</a></li>
  </ul>
  
  <p>...but they either deal only with a limited set of TLDs or are not that bothered by reliability.</p>