CrowdStrike FalconPy SDK
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
- breaking Python 3.7 support was dropped in FalconPy v1.6.0. Projects using Python 3.7 or older will fail to install or run this version.
- deprecated Specific API operations are periodically deprecated or replaced. For example, `combinedUserRolesV1` was deprecated in v1.5.1 in favor of `CombinedUserRolesV2`.
- gotcha The `base_url` parameter must be set correctly for your CrowdStrike cloud region (e.g., api.us-1.crowdstrike.com, api.eu-1.crowdstrike.com). The default is `https://api.crowdstrike.com` (US-1).
- gotcha API responses should always be checked for `status_code` and the presence of an `errors` key in the response body. A successful HTTP status code (e.g., 200) does not always guarantee the absence of application-level errors.
- gotcha Service collection names and their associated operations can change over time. For example, 'Compliance Assessments' was renamed to 'Container Image Compliance' in v1.4.9.
Install
-
pip install crowdstrike-falconpy
Imports
- APIHarness
from falconpy import APIHarness
- HostGroup
from falconpy import HostGroup
Quickstart
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}")