Filigran SSEClient

1.0.2 · active · verified Thu Apr 16

Filigran SSEClient provides a Python API client specifically designed for consuming Server-Sent Events (SSE) from OpenCTI platforms. It simplifies connection management, event parsing, and authentication for real-time data streaming from OpenCTI. The current version is 1.0.2, and releases are typically made to address bug fixes or minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to an OpenCTI Server-Sent Events stream using `filigran-sseclient`. It initializes an `SSEClient` with a base URL and API key (retrieved from environment variables for security) and then iterates through incoming events. Remember to replace placeholder values with your actual OpenCTI instance details and ensure `OPENCTI_API_KEY` is securely configured.

import os
from filigran_sseclient import SSEClient

# Replace with your OpenCTI instance URL and API key/token
OPENCTI_BASE_URL = os.environ.get('OPENCTI_BASE_URL', 'https://demo.opencti.io')
OPENCTI_API_KEY = os.environ.get('OPENCTI_API_KEY', '') # Ensure this is set securely

if not OPENCTI_API_KEY:
    print("WARNING: OPENCTI_API_KEY environment variable not set. Connection may fail or use a public demo instance.")

print(f"Attempting to connect to OpenCTI SSE at {OPENCTI_BASE_URL}...")

try:
    client = SSEClient(
        base_url=OPENCTI_BASE_URL,
        api_key=OPENCTI_API_KEY,
        verify=False # Set to True in production with proper SSL certificates
    )

    print("Connected. Waiting for events...")
    for event in client.events():
        print(f"Received Event - ID: {event.id}, Type: {event.event}, Data: {event.data}")
        # Process event.event (e.g., 'create', 'update', 'delete')
        # Process event.data (usually JSON string of the OpenCTI object)
        # For demonstration, break after a few events or on a specific condition
        if event.id and int(event.id) > 5: # Example: process first 5 events
            break

except Exception as e:
    print(f"An error occurred during SSE connection or event processing: {e}")
finally:
    print("SSE client connection terminated.")

view raw JSON →