Socket Security Python SDK

3.0.32 · active · verified Fri Apr 17

The Socket Security Python SDK provides an interface to interact with the Socket API for software supply chain security scanning. It allows users to scan packages, retrieve security insights, and manage their Socket account programmatically. The current version is 3.0.32, and it follows an active release cadence with regular updates.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the SocketSDKClient using an API key (preferably from an environment variable) and performs a basic package scan. Demonstrates handling of the returned `ScanPackageResult` object.

import os
import socketdev

# Ensure you have SOCKET_API_KEY set as an environment variable or pass api_key directly
# e.g., os.environ['SOCKET_API_KEY'] = 'your_api_key_here'

try:
    client = socketdev.SocketSDKClient(api_key=os.environ.get('SOCKET_API_KEY', ''))

    # Example: Scan a package (npm, lodash, v4.17.21)
    result = client.scan_package(
        ecosystem="npm", 
        package="lodash", 
        version="4.17.21", 
        options={"allow_insecure_versions": True}
    )
    print(f"Scan status: {result.status}")
    print(f"Issue count: {result.issues_count}")
    
    # Accessing specific issues if available
    if result.issues:
        print("First issue type:", result.issues[0].issue_type)

except socketdev.exceptions.SocketApiException as e:
    print(f"API Error: {e.status_code} - {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →