Sumo Logic Python SDK

0.1.17 · active · verified Thu Apr 16

The Sumo Logic Python SDK (version 0.1.17) is a community-supported Python interface to the Sumo Logic REST API, designed to simplify interactions with the API in Python code. It provides functionality for various API operations, including content management, search, and collector interactions. The library maintains an active development status with periodic updates, with the latest release in June 2024.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the `SumoLogic` client using credentials and an API endpoint, then fetches and prints the first few Sumo Logic collectors. Ensure you have your `SUMO_ACCESS_ID`, `SUMO_ACCESS_KEY`, and `SUMO_ENDPOINT` set as environment variables. The endpoint should match your Sumo Logic deployment (e.g., `https://api.us2.sumologic.com/api`).

import os
from sumologic import SumoLogic

# Set your Sumo Logic Access ID, Access Key, and API endpoint as environment variables
# e.g., export SUMO_ACCESS_ID='your_access_id'
#       export SUMO_ACCESS_KEY='your_access_key'
#       export SUMO_ENDPOINT='https://api.sumologic.com/api' (or your region-specific endpoint)

access_id = os.environ.get('SUMO_ACCESS_ID', '')
access_key = os.environ.get('SUMO_ACCESS_KEY', '')
endpoint = os.environ.get('SUMO_ENDPOINT', 'https://api.sumologic.com/api') # Default for US1

if not all([access_id, access_key, endpoint]):
    print("Error: SUMO_ACCESS_ID, SUMO_ACCESS_KEY, and SUMO_ENDPOINT environment variables must be set.")
else:
    try:
        # Initialize the Sumo Logic client
        sumo = SumoLogic(access_id, access_key, endpoint)

        # Example: Get a list of all collectors
        collectors = sumo.get_collectors_sync()

        print(f"Successfully connected to Sumo Logic. Found {len(collectors)} collectors.")
        for collector in collectors[:3]: # Print first 3 collectors for brevity
            print(f"  - ID: {collector['id']}, Name: {collector['name']}")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →