Scarf SDK

0.2.1 · active · verified Thu Apr 16

Scarf's Python SDK is a client library for sending telemetry events to Scarf, typically using JSON payloads. It provides open-source software maintainers with deep insights into how their projects are being used, by which companies, and more, aiding in understanding reach and identifying growth opportunities. The library is actively maintained with consistent minor updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ScarfEventLogger` with a Scarf endpoint URL and send a custom telemetry event with a JSON payload. It also highlights how users can opt-out using environment variables.

import os
from scarf import ScarfEventLogger

# Initialize with your Scarf endpoint URL. This is typically found in your Scarf dashboard.
# For a runnable example, we use an environment variable or a placeholder.
endpoint_url = os.environ.get('SCARF_ENDPOINT_URL', 'https://your-scarf-endpoint.com')

logger = ScarfEventLogger(
    endpoint_url=endpoint_url,
    timeout=5.0 # Optional: Set a default timeout in seconds (default is 3.0)
)

# Send an event with properties (JSON payload)
success = logger.log_event({
    "event": "package_function_call",
    "package": "my_python_library",
    "details": {
        "version": "1.2.3",
        "feature": "data_processing",
        "user_id": "anon_user_123"
    }
})

if success:
    print("Telemetry event sent successfully.")
else:
    print("Failed to send telemetry event.")

# Telemetry can be disabled by users via environment variables:
# DO_NOT_TRACK=1 or SCARF_NO_ANALYTICS=1

view raw JSON →