CrowdStrike FalconPy SDK

1.6.1 · active · verified Sat Apr 11

CrowdStrike FalconPy is the official Python SDK for interacting with CrowdStrike Falcon APIs. It provides a standardized way to access various CrowdStrike services, enabling automation and integration. The library is currently at version 1.6.1 and receives frequent updates, typically focusing on new API operations, bug fixes, and minor enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the FalconPy APIHarness client using environment variables for authentication and retrieve the CrowdStrike Customer ID (CID). It highlights the recommended practice of externalizing credentials and includes basic error handling for API responses.

import os
from falconpy import APIHarness

# Retrieve credentials from environment variables
client_id = os.environ.get('FALCON_CLIENT_ID', '')
client_secret = os.environ.get('FALCON_CLIENT_SECRET', '')
base_url = os.environ.get('FALCON_BASE_URL', 'https://api.crowdstrike.com')

if not client_id or not client_secret:
    print("Please set FALCON_CLIENT_ID and FALCON_CLIENT_SECRET environment variables.")
else:
    try:
        # Initialize the APIHarness client
        falcon = APIHarness(client_id=client_id, 
                            client_secret=client_secret, 
                            base_url=base_url)
        
        # Example: Get the Customer ID (CID)
        response = falcon.get_cid()
        
        if response['status_code'] == 200:
            print(f"Successfully connected. Customer ID: {response['body']['cid']}")
        else:
            print(f"Error getting CID: {response['status_code']} - {response.get('body', {}).get('errors', 'Unknown error')}")
            
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →