TAXII 2 Client Library

2.3.0 · active · verified Thu Apr 16

taxii2-client is a minimal Python client library for the Trusted Automated eXchange of Indicator Information (TAXII) 2.x specification. It supports both TAXII 2.0 and 2.1, enabling interaction with TAXII servers for cyber threat intelligence (CTI) exchange, including server discovery, API root information, collection management, and object retrieval/addition. It is currently at version 2.3.0 and is maintained by OASIS Open as an OASIS TC Open Repository.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart connects to a TAXII 2.1 server, authenticates, retrieves available API Roots, and then lists the collections within each root. It demonstrates basic server and API root discovery. Authentication details are stored in the `Server` instance for subsequent requests.

import os
from taxii2client.v21 import Server

# Replace with your TAXII server URL and credentials
TAXII_SERVER_URL = os.environ.get('TAXII_SERVER_URL', 'https://example.com/taxii2/')
TAXII_USER = os.environ.get('TAXII_USER', 'guest')
TAXII_PASSWORD = os.environ.get('TAXII_PASSWORD', 'guest_password')

try:
    # Initialize the Server object
    server = Server(TAXII_SERVER_URL, user=TAXII_USER, password=TAXII_PASSWORD)
    print(f"Connected to TAXII Server: {server.title}")

    # Iterate through API Roots
    for api_root in server.api_roots:
        print(f"\n  API Root: {api_root.title} ({api_root.versions})")
        
        # Iterate through Collections in each API Root
        for collection in api_root.collections:
            print(f"    Collection ID: {collection.id}, Title: {collection.title}, Can Read: {collection.can_read}")

            # Example: Fetching objects from a readable collection (optional)
            if collection.can_read:
                # This is a simplified example; real-world usage might require pagination (as_pages)
                # and filtering. 'objects' attribute is lazy-loaded.
                # objects_gen = collection.get_objects(limit=10) # For paginated requests
                # for obj in objects_gen:
                #     print(f"        Object ID: {obj['id']}")
                pass

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

view raw JSON →