Skip to main content

DNSAudit Python SDK

The official Python SDK for the DNSAudit.io API.

Seamlessly perform comprehensive DNS security audits, detect misconfigurations, bypass caching, and export detailed PDF/JSON reports directly from your Python applications. Built with modern httpx, this SDK provides both Synchronous and Asynchronous execution!

Installation

You can install the package directly via pip:

pip install dnsaudit

Requires Python 3.8+

Authentication

The SDK requires a DNSAudit API Key. The easiest and most secure way is to set it as an environment variable. The SDK will automatically detect it:

export DNSAUDIT_API_KEY="your-api-key"

Alternatively, you can pass it directly into the Client:

from dnsaudit import Client

client = Client(api_key="your-api-key")

Examples

We provide ready-to-run sample scripts inside the examples/ directory. If you are new to the SDK, we highly recommend checking out examples/basic_scan.py to see how a complete script is structured!


Complete Usage Guide (Synchronous)

The standard Client provides a smooth, blocking interface (similar to requests). It automatically manages connection pools, so using a with block is highly recommended!

1. Basic Scanning & Bypassing Cache

By default, the DNSAudit API caches results for 24 hours. You can force a fresh scan by passing no_cache=True.

from dnsaudit import Client

with Client() as client:
    # 1. Run a fresh scan (bypasses the 24-hour cache)
    print("Initiating fresh scan...")
    result = client.scan("example.com", no_cache=True)
    
    # The result is a raw Python dictionary containing the full JSON response
    grade = result['grade']['grade']
    score = result['grade']['score']
    print(f"Result for example.com: Grade {grade} (Score: {score})")

2. Exporting PDF & JSON Reports

You can download full reports programmatically.

from dnsaudit import Client

with Client() as client:
    # Export a beautiful PDF report and save it to your disk
    pdf_bytes = client.export_pdf("example.com")
    with open("security_report.pdf", "wb") as f:
        f.write(pdf_bytes)
    print("Saved security_report.pdf!")

    # Or export the raw JSON data dump
    json_dump = client.export_json("example.com")
    print(f"Total issues found: {len(json_dump.get('issues', []))}")

3. Viewing Account Scan History

Easily retrieve your past scans.

from dnsaudit import Client

with Client() as client:
    # Fetch the 5 most recent scans on your account
    history = client.get_history(limit=5)
    
    print("Recent Scans:")
    for scan in history.get('scans', []):
        print(f"- {scan['domain']} (Grade: {scan['grade']})")

High-Performance Asynchronous Execution

If you are building an async application (e.g., FastAPI, a Discord bot, or a mass-scanning tool), you can use the non-blocking AsyncClient to achieve massive concurrency.

import asyncio
from dnsaudit import AsyncClient

async def mass_scan(domains):
    async with AsyncClient() as client:
        # Create a list of concurrent async tasks
        tasks = [client.scan(domain, no_cache=True) for domain in domains]
        
        # Execute them all simultaneously
        results = await asyncio.gather(*tasks)
        
        for res in results:
            print(f"{res['domain']}: {res['grade']['grade']}")

if __name__ == "__main__":
    target_domains = ["example.com", "github.com", "google.com"]
    asyncio.run(mass_scan(target_domains))

Intelligent Rate Limiting

The DNSAudit API strictly enforces daily quotas and burst limits. The Python SDK automatically handles burst limits (HTTP 429) for you.

If you send too many requests too quickly, the SDK will intercept the API's Retry-After payload, automatically pause your script for the exact right number of seconds, and seamlessly retry the request. You do not need to write any manual retry logic or time.sleep() loops!

Error Handling

The SDK provides robust custom exception classes so you can easily catch and handle specific errors:

from dnsaudit import Client, AuthenticationError, RateLimitError, APIError, DNSAuditError

try:
    with Client(api_key="invalid-key") as client:
        client.scan("example.com")
        
except AuthenticationError as e:
    print(f"Authentication Failed: Ensure your API key is correct. ({e})")
except RateLimitError as e:
    print(f"Daily quota exceeded! ({e})")
except APIError as e:
    print(f"The server returned an error: {e}")
except DNSAuditError as e:
    print(f"A general SDK error occurred: {e}")

Metadata

Release files for dnsaudit 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnsaudit 1.0.0
File Size Uploaded Provenance
dnsaudit-1.0.0.tar.gz 5.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dnsaudit 1.0.0
File Interpreter ABI Platform
dnsaudit-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / dnsaudit-1.0.0.tar.gz

Download URL dnsaudit-1.0.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fa80fb2bdca41d07b8d62ee5e74375d57c2d78aaef9740b823f0b922416eee5d
BLAKE2b-256 checksum
How to use checksums
55b6d897425fde0b56a926856d5dbead87e162c72b9c77a61c934ae4e75f8cf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / dnsaudit-1.0.0-py3-none-any.whl

Download URL dnsaudit-1.0.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27804f5c12fac17910e31c74249bd5b8185d8c4010aee419e0ce7d88768a5ee8
BLAKE2b-256 checksum
How to use checksums
de458010bcbb998d47a599e4f6529eefb6d65ea9dd538dda7d6dbf4442d47c7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for dnsaudit 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page