dnspython is a comprehensive DNS toolkit for Python, currently at version 2.8.0, supporting Python 3.10 and above. It is actively maintained and follows a regular release cadence.
Install & Compatibility
Where this runs
tested against v2.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.925 runs
installs and imports cleanly · install 0.0s · import 0.221s · 20.3MB
glibcpy 3.10–3.925 runs
installs and imports cleanly · install 1.7s · import 0.194s · 21MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
dns.resolver
✓ import dns.resolver
Ensure 'dns' is not shadowed by a local module named 'dns'.
dns.query
✓ import dns.query
Ensure 'dns' is not shadowed by a local module named 'dns'.
This script queries the A records for 'example.com' and prints each IP address.
import dns.resolver
# Query for A records of 'example.com'
result = dns.resolver.resolve('example.com', 'A')
for ipval in result:
print('IP', ipval.to_text())
dnspython --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dns'
The `dnspython` package, which provides the `dns` module, is not installed in the Python environment, or the environment where it's installed is not the one being used.
fixInstall the `dnspython` package using pip: `pip install dnspython`
ModuleNotFoundError: No module named 'dnspython'
Developers often try to import `dnspython` using `import dnspython`, but the primary module to import from the `dnspython` package is `dns` (e.g., `import dns.resolver`).
fixChange your import statement from `import dnspython` to `import dns` (or more specifically, `import dns.resolver`, `import dns.message`, etc., depending on what you need).
dns.resolver.NXDOMAIN: None of DNS query names exist
This error occurs when the queried domain name does not exist according to the configured DNS nameservers. This can be due to a typo in the domain, the domain truly not existing, or issues with the nameservers being used.
fixVerify the domain name for typos. If the name is correct, try configuring the resolver to use different or public nameservers (e.g., Google's 8.8.8.8) using `resolver = dns.resolver.Resolver(); resolver.nameservers = ['8.8.8.8']` or explicitly checking different nameservers.
dns.resolver.NoAnswer
This exception is raised when the queried domain name exists, but there is no DNS record of the specific type requested (e.g., asking for an MX record where only A records exist).
fixCatch the `dns.resolver.NoAnswer` exception in a `try-except` block to handle cases where no record of the specified type is found. Alternatively, when using `resolver.query()`, set `raise_on_no_answer=False` if you want to inspect the response even if no answer section is present.
dns.resolver.LifetimeTimeout: The resolution lifetime expired
The DNS query or the overall resolution process took longer than the specified `lifetime` or `timeout` setting, meaning no response was received from any nameserver within the allotted time. This often indicates network issues, slow DNS servers, or restrictive firewall rules.
fixIncrease the `lifetime` and/or `timeout` parameters for your resolver. For example: `resolver = dns.resolver.Resolver(); resolver.timeout = 5; resolver.lifetime = 10`. Also, ensure that your network configuration allows DNS queries to the target nameservers.
Audit
Dependencies
No dependency data recorded yet.