SDKs overview

SecurityTrails provides Software Development Kits (SDKs) and community-contributed libraries to facilitate programmatic interaction with its threat intelligence API. These tools enable developers to integrate SecurityTrails's extensive datasets—including historical and current DNS, WHOIS, and IP information—directly into their custom applications, security tools, and automated workflows. The primary objective of these SDKs is to abstract the complexities of HTTP requests, authentication, and response parsing, allowing developers to focus on data utilization rather than API mechanics. Official SDKs are maintained for Python and PHP, offering structured access to various API endpoints such as domain lookups, IP address investigations, and data feeds. Community efforts have also extended support to other languages, reflecting developer interest in integrating SecurityTrails data into diverse technological stacks.

Integrating with the SecurityTrails API typically involves an API key for authentication, ensuring secure access to data. This key is passed in the request header, a standard practice for RESTful API authentication as outlined by various security guidelines, including those for general web API security practices on developer.mozilla.org. The choice between an official SDK and a community library often depends on the developer's preferred programming language, project requirements, and the level of active maintenance and support available for each tool. Both official and community options aim to reduce development time and enhance the efficiency of data retrieval for tasks like threat hunting, asset inventory management, and open-source intelligence (OSINT) gathering.

Official SDKs by language

SecurityTrails maintains official SDKs for popular programming languages, ensuring direct and supported access to its API features. These SDKs are developed and updated by SecurityTrails to align with the latest API versions and best practices. The official Python SDK, known as securitytrails-py, provides a comprehensive client for interacting with all major API endpoints, including domain search, historical DNS records, WHOIS data, and IP neighborhood information. Similarly, the official PHP SDK offers analogous functionality for PHP-based applications. These SDKs handle details such as API key management, request serialization, and response deserialization, presenting data in native language structures.

The table below summarizes the key official SDKs provided by SecurityTrails:

Language Package Name Installation Command Maturity Key Features
Python securitytrails-py pip install securitytrails-py Stable Domain and IP data retrieval, historical DNS records, WHOIS data, bulk lookups.
PHP securitytrails/securitytrails-php composer require securitytrails/securitytrails-php Stable Access to domain and IP endpoints, DNS history, WHOIS information, association data.

These SDKs are designed to offer a consistent and reliable interface, reducing the boilerplate code required for API interactions. Developers can find detailed usage examples and API endpoint mappings in the SecurityTrails official documentation, which includes specific instructions for configuring and using each SDK.

Installation

Installing SecurityTrails SDKs and libraries typically follows standard package management procedures for each respective programming language. For Python, the official SDK is available via PyPI (Python Package Index), making installation straightforward with pip. PHP developers can utilize Composer, the dependency manager for PHP, to integrate the official PHP SDK into their projects. Community libraries for other languages, such as Ruby, Go, and Rust, also adhere to their respective language ecosystems' installation practices, often using tools like RubyGems, go get, or Cargo.

Python SDK Installation

To install the official Python SDK, ensure you have Python and pip installed on your system. Open your terminal or command prompt and execute the following command:

pip install securitytrails-py

This command downloads and installs the latest version of the securitytrails-py package and its dependencies. After installation, you can import the library into your Python scripts.

PHP SDK Installation

For PHP projects, Composer is the recommended tool for managing dependencies. If you don't have Composer, you can find installation instructions on the official Composer download page. Once Composer is set up, navigate to your project directory in the terminal and run:

composer require securitytrails/securitytrails-php

This command adds the SecurityTrails PHP SDK to your composer.json file and installs it into your project's vendor/ directory, making it available for use in your PHP application.

For community-contributed libraries, developers should consult the specific project's documentation on platforms like GitHub to understand their unique installation requirements and dependencies. These often involve similar package management commands specific to their language environments.

Quickstart example

This quickstart example demonstrates how to use the official Python SDK to retrieve current DNS records for a specified domain. Before running this code, ensure you have installed the securitytrails-py package as described in the installation section and have a valid SecurityTrails API key. Your API key can be obtained from your SecurityTrails account dashboard.

Python Quickstart: Get Current DNS Records

The following Python script initializes the SecurityTrails client with your API key and then makes a request to fetch the current DNS records for a domain. The response is then printed to the console, demonstrating how to access the structured data returned by the API.

from securitytrails.securitytrails import SecurityTrails
import os

# Replace with your actual SecurityTrails API key
# It's recommended to load your API key from environment variables
# export ST_API_KEY="YOUR_API_KEY_HERE"
api_key = os.environ.get("ST_API_KEY")

if not api_key:
    print("Error: SecurityTrails API key not found. Please set the 'ST_API_KEY' environment variable.")
    exit()

# Initialize the SecurityTrails client
st = SecurityTrails(api_key)

# Define the domain for which to retrieve DNS records
domain = "example.com"

try:
    # Fetch current DNS records for the domain
    # For detailed API endpoint specifics, refer to the SecurityTrails API reference
    # at https://docs.securitytrails.com/reference/api-overview
    dns_data = st.domain.current_dns(domain)

    print(f"Current DNS records for {domain}:")
    for record_type, records in dns_data.items():
        print(f"  {record_type}:")
        for record in records:
            print(f"    - {record}")

except Exception as e:
    print(f"An error occurred: {e}")

To run this example:

  1. Save the code as a .py file (e.g., get_dns.py).
  2. Set your SecurityTrails API key as an environment variable named ST_API_KEY, or replace os.environ.get("ST_API_KEY") with your key string directly (not recommended for production).
  3. Execute the script from your terminal: python get_dns.py.

This script provides a foundational understanding of how to interact with the SecurityTrails API using the Python SDK. Developers can adapt this pattern to access other API endpoints, such as historical WHOIS data or IP address neighbors, by consulting the SecurityTrails API reference for specific method calls and parameters.

Community libraries

Beyond the officially supported SDKs, the SecurityTrails developer community has contributed a variety of libraries and wrappers in other programming languages. These community-driven projects extend the reach of SecurityTrails API integration to environments like Ruby, Go, and Rust, catering to developers with diverse language preferences. While these libraries may not receive the same direct support or regular updates as official SDKs, they can offer valuable tools for specific use cases or development ecosystems.

Examples of community contributions include:

  • Ruby Gem: A Ruby client library allows Ruby developers to interact with the SecurityTrails API, often mirroring the functionality of the official Python SDK by providing methods for domain and IP lookups. These are typically available on platforms like RubyGems.
  • Go (Golang) Client: For Go developers, community wrappers can offer idiomatic Go interfaces to query SecurityTrails data, leveraging Go's concurrency features for efficient data retrieval in large-scale applications.
  • Rust Crates: Rust developers might find crates that provide safe and performant bindings to the SecurityTrails API, aligning with Rust's focus on system-level programming and reliability.

When considering a community library, it is advisable to evaluate its active maintenance, documentation quality, and community support on platforms such as GitHub. Developers should also review the source code for security practices and ensure compatibility with the latest SecurityTrails API versions. These libraries often leverage standard HTTP client libraries available in their respective languages, such as HTTP methods defined by the W3C for web interactions, to construct and send requests to the API endpoints. While they provide flexibility, developers are generally responsible for monitoring updates and potential breaking changes in these community-maintained projects.