PyMISP

2.5.33.1 · active · verified Sun Apr 12

PyMISP is a Python library designed to interact with MISP (Malware Information Sharing Platform) instances via their REST API. It provides comprehensive functionalities to fetch, add, update, and search for events, attributes, objects, samples, and more, facilitating automated threat intelligence sharing and analysis. The library is actively maintained with frequent releases, ensuring compatibility with the latest MISP features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the PyMISP object using environment variables for the MISP URL and API key, and then how to fetch the last 5 published events. It includes basic error handling for connection issues.

import os
from pymisp import PyMISP

# Configure MISP connection from environment variables
misp_url = os.environ.get('MISP_URL', 'https://your.misp.instance')
misp_key = os.environ.get('MISP_KEY', 'YOUR_MISP_AUTOMATION_KEY') # Your MISP automation key
misp_verifycert = os.environ.get('MISP_VERIFYCERT', 'True').lower() == 'true'

# Initialize PyMISP object
try:
    misp = PyMISP(misp_url, misp_key, misp_verifycert)
    print(f"Successfully connected to MISP instance at {misp_url}.")

    # Example: Fetch last 5 published events
    last_events = misp.search(limit=5, controller='events', published=True)
    if last_events:
        print(f"Found {len(last_events)} published events:")
        for event in last_events:
            print(f"  Event ID: {event['Event']['id']}, Info: {event['Event']['info']}")
    else:
        print("No published events found in the last search.")

except Exception as e:
    print(f"Error connecting to MISP or fetching events: {e}")
    print("Please ensure MISP_URL, MISP_KEY, and MISP_VERIFYCERT are correctly set.")

view raw JSON →