CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-taxii2-client

Python TAXII 2.X client library for sharing cyber threat intelligence via STIX protocol

Overview
Eval results
Files

server-discovery.mddocs/

Server Discovery

Server-level operations for discovering TAXII services, API roots, and server capabilities. The Server class provides the entry point for all TAXII interactions by connecting to a TAXII discovery endpoint.

Capabilities

Server Connection

Connect to a TAXII server discovery endpoint with authentication and SSL options.

class Server:
    def __init__(self, url, conn=None, user=None, password=None, verify=True, 
                 proxies=None, auth=None, cert=None):
        """
        Create a TAXII server discovery endpoint connection.
        
        Parameters:
        - url (str): URL of TAXII server discovery endpoint
        - conn (_HTTPConnection, optional): Reuse existing connection
        - user (str, optional): Username for HTTP basic authentication
        - password (str, optional): Password for HTTP basic authentication
        - verify (bool): Validate SSL certificates (default: True)
        - proxies (dict, optional): HTTP/HTTPS proxy settings
        - auth (requests.auth.AuthBase, optional): Custom authentication object
        - cert (str or tuple, optional): SSL client certificate path or (cert, key) tuple
        """

Server Information

Access server metadata including title, description, contact information, and available API roots.

@property
def title(self) -> str:
    """Server title (required)."""

@property 
def description(self) -> str:
    """Server description (optional)."""

@property
def contact(self) -> str:
    """Server contact information (optional)."""

@property
def default(self) -> ApiRoot:
    """Default API root instance (optional)."""

@property
def api_roots(self) -> list[ApiRoot]:
    """List of available API root instances (optional)."""

@property
def custom_properties(self) -> dict:
    """Custom server properties not defined in TAXII spec."""

@property
def _raw(self) -> dict:
    """Raw server discovery response (parsed JSON)."""

Server Operations

Refresh server information and manage the discovery connection.

def refresh(self) -> None:
    """Update server information and list of API roots."""

def close(self) -> None:
    """Close the server connection."""

def __enter__(self):
    """Context manager entry."""

def __exit__(self, exc_type, exc_val, exc_tb):
    """Context manager exit."""

Usage Examples

Basic Server Connection

from taxii2client import Server

# Connect with basic authentication
server = Server(
    url="https://taxii-server.example.com/taxii2/",
    user="username",
    password="password"
)

print(f"Connected to: {server.title}")
print(f"Description: {server.description}")
print(f"Contact: {server.contact}")

Advanced Authentication

from taxii2client import Server
from taxii2client.common import TokenAuth
import requests.auth

# Token authentication
token_auth = TokenAuth("your-api-token")
server = Server(
    url="https://taxii-server.example.com/taxii2/",
    auth=token_auth
)

# Custom authentication
custom_auth = requests.auth.HTTPDigestAuth("user", "pass")
server = Server(
    url="https://taxii-server.example.com/taxii2/",
    auth=custom_auth
)

# SSL client certificate
server = Server(
    url="https://taxii-server.example.com/taxii2/",
    cert=("/path/to/client.crt", "/path/to/client.key")
)

Working with API Roots

server = Server("https://taxii-server.example.com/taxii2/")

# Access default API root
if server.default:
    api_root = server.default
    print(f"Using default API root: {api_root.title}")
else:
    # Use first available API root
    api_root = server.api_roots[0]
    print(f"Using API root: {api_root.title}")

# List all available API roots
print(f"Available API roots ({len(server.api_roots)}):")
for i, root in enumerate(server.api_roots):
    print(f"  {i+1}. {root.title}")
    print(f"     URL: {root.url}")
    print(f"     Versions: {', '.join(root.versions)}")

Context Manager Usage

# Automatically handle connection cleanup
with Server("https://taxii-server.example.com/taxii2/") as server:
    print(f"Server: {server.title}")
    for api_root in server.api_roots:
        print(f"API Root: {api_root.title}")
        # Connection automatically closed when exiting context

Proxy and SSL Options

# Configure proxy settings
proxies = {
    'http': 'http://proxy.example.com:8080',
    'https': 'https://proxy.example.com:8080'
}

server = Server(
    url="https://taxii-server.example.com/taxii2/",
    proxies=proxies,
    verify=False  # Disable SSL verification (not recommended for production)
)

# Custom SSL CA bundle
server = Server(
    url="https://taxii-server.example.com/taxii2/",
    verify="/path/to/ca-bundle.crt"
)

Install with Tessl CLI

npx tessl i tessl/pypi-taxii2-client

docs

api-root-management.md

authentication-connection.md

collection-operations.md

index.md

pagination-support.md

server-discovery.md

status-monitoring.md

tile.json