DomainTools Python API

2.7.3 · active · verified Thu Apr 16

The DomainTools Python API Wrapper provides a unified interface to interact with DomainTools' cybersecurity and threat intelligence products, including Iris Investigate, Iris Enrich, Iris Detect, Lookups, Monitors, and Threat Feeds. It is actively maintained, currently at version 2.7.3, with frequent minor releases addressing bugs and ensuring API parity.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the API client with your DomainTools username and API key. The library supports various DomainTools API endpoints, including Domain Profile lookups, Iris Enrich, and Real-Time Threat Feeds. Credentials should ideally be stored as environment variables (DOMAINTOOLS_USERNAME, DOMAINTOOLS_API_KEY) for security.

import os
from domaintools import API

# Best practice: Store credentials securely in environment variables
username = os.environ.get('DOMAINTOOLS_USERNAME', 'your_username')
api_key = os.environ.get('DOMAINTOOLS_API_KEY', 'your_api_key')

# Initialize the API client
try:
    api = API(username, api_key)

    # Example 1: Domain Profile lookup
    profile_result = api.domain_profile('example.com')
    print(f"Domain Profile for example.com: {profile_result.response()['domain']}")

    # Example 2: Iris Enrich
    enrich_result = api.iris_enrich('domaintools.com')
    for domain_data in enrich_result.response().get('results', {}):
        print(f"Enriched domain: {domain_data['domain']}, Risk Score: {domain_data['domain_risk']['risk_score']}")
        break # Just print one for brevity

    # Example 3: Real-Time Threat Feed (New Observed Domains - NOD)
    # Threat Feeds automatically use header authentication, handled by SDK
    # Use sessionID for pagination or 'after' parameter for time range
    nod_feed = api.nod(after=-3600) # Last hour
    for record_json in nod_feed.response():
        # Records are JSON strings, need to parse them
        import json
        record = json.loads(record_json)
        print(f"New observed domain from feed: {record['domain']}")
        break # Just print one for brevity

except Exception as e:
    print(f"An error occurred: {e}")
    if username == 'your_username' or api_key == 'your_api_key':
        print("Please set DOMAINTOOLS_USERNAME and DOMAINTOOLS_API_KEY environment variables or replace placeholders.")

view raw JSON →