Surge Python SDK

1.5.21 · active · verified Mon Apr 13

The Surge Python SDK (current version 1.5.21) provides convenient access to the Surge AI API, enabling applications to interact with the Surge AI platform for data annotation, human intelligence tasks, and managing projects. It is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with the Surge AI API using an environment variable and then list existing projects. It also shows how to retrieve a specific project by its ID. Remember to set the `SURGE_API_KEY` environment variable.

import surge
import os

# Set your Surge AI API key from an environment variable
surge.api_key = os.environ.get('SURGE_API_KEY', '')

if not surge.api_key:
    print("Error: SURGE_API_KEY environment variable not set.")
else:
    try:
        # List all projects under your Surge account
        projects = surge.Project.list()
        if projects:
            print(f"Successfully retrieved {len(projects)} projects.")
            print(f"First project name: {projects[0].name}")
            
            # Retrieve a specific project by ID (replace with a real ID if available)
            # For demonstration, we'll try to retrieve the first project by its ID
            project_id = projects[0].id
            single_project = surge.Project.retrieve(project_id)
            print(f"Retrieved project by ID: {single_project.name}")
            
            # Example: Download results (uncomment and adjust as needed)
            # results = single_project.download_json()
            # print(f"Downloaded results for {single_project.name}: {results[:100]}...")

        else:
            print("No projects found in your Surge AI account.")

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

view raw JSON →