Download Markdown

Python and Go SDKs

By the end of this page you’ll have an SDK installed and use it to search and read full bodies. SDKs use your API key, with the same access as calling the API directly.

No key yet? See Get an API key. Downloading an SDK doesn’t require signing in.

Python

Requires Python 3.10 or later.

Bash
curl -fsSL https://www.marsyoo.com/api/sdk/python-consumer \
  -o marsyoo-python-consumer-sdk-v0.2.0.tar.gz
tar -xzf marsyoo-python-consumer-sdk-v0.2.0.tar.gz
cd marsyoo-python-consumer-sdk-v0.2.0
python3 -m venv .venv
. .venv/bin/activate
python -m pip install .

Put your key in the WHALE_API_KEY environment variable, then:

Python
import os
from whale_consumer import Client
 
client = Client(api_key=os.environ["WHALE_API_KEY"], timeout=30)
result = client.search(query="artificial intelligence", mode="keyword", limit=10)
for item in result.get("results", []):
    document_id = item["document_id"]
    content = client.get_document_content(document_id)
    print(document_id, content.get("content", {}).get("body", ""))

When document IDs and bodies print, it works. With no results nothing prints; the SDK never starts collection on its own.

Go

  1. Download the Go SDK, unpack it, and run go test ./... in the package directory.
  2. Reference the local module from your project, replacing the path with the real absolute path:
Bash
go mod edit -require=whale/sdk/go/consumer@v0.0.0
go mod edit -replace=whale/sdk/go/consumer=/absolute/path/to/marsyoo-go-consumer-sdk-v0.2.0
  1. In main.go:
Go
package main
 
import (
    "context"
    "fmt"
    "log"
    "os"
    "time"
 
    consumer "whale/sdk/go/consumer"
)
 
func main() {
    key := os.Getenv("WHALE_API_KEY")
    if key == "" {
        log.Fatal("Set WHALE_API_KEY")
    }
    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()
    client := consumer.New("https://www.marsyoo.com", key)
    result, err := client.Search(ctx, consumer.SearchRequest{Query: "AI", Mode: "keyword", Limit: 10})
    if err != nil {
        log.Fatal(err)
    }
    for _, item := range result.Results {
        content, err := client.GetDocumentContent(ctx, item.DocumentID, "")
        if err != nil {
            log.Fatal(err)
        }
        fmt.Println(item.DocumentID, content.Content["body"])
    }
}
  1. Run go mod tidy, then go run ..

The README in the SDK package also has a change feed example.

Browse by topic

Python
page = client.browse_documents(
    topics=["AI"],
    created_from="2026-10-01T00:00:00Z",
    created_to="2026-10-02T00:00:00Z",
    limit=50,
)
for item in page.get("documents", []):
    print(item["document"]["id"])

For the next page, keep the parameters and pass the returned next_cursor as cursor.

Methods and endpoints

UsePythonGoEndpoint
SearchsearchSearchPOST /v1/search
Search stored data onlysearch_historySearchHistoryPOST /v1/search/history
Browse by filtersbrowse_documentsBrowseDocumentsGET /v1/documents/browse
User profileget_userGetUserGET /v1/users/{platform}/{id}
A user’s documentslist_user_documentsListUserDocumentsGET /v1/users/{platform}/{id}/documents
Category dictionarylist_classificationsListClassificationsGET /v1/classifications
Document metadataget_documentGetDocumentGET /v1/documents/{id}
Full bodyget_document_contentGetDocumentContentGET /v1/documents/{id}/content
Batch readbatch_getBatchGetPOST /v1/documents/batch-get
Version historylist_document_versionsListDocumentVersionsGET /v1/documents/{id}/versions
Metric snapshotslist_document_snapshotsListDocumentSnapshotsGET /v1/documents/{id}/snapshots
Subtitles, OCR and other partslist_document_partsListDocumentPartsGET /v1/documents/{id}/parts
Factslist_document_factsListDocumentFactsGET /v1/documents/{id}/facts
Attachments and download linkslist_attachments、get_attachment_download_urlListAttachments、GetAttachmentDownloadURLGET /v1/documents/{id}/attachments…
Change feedlist_changes、iter_change_pagesListChanges、NewChangesIteratorGET /v1/changes
Live queriescreate_live_query、get_live_query、list_live_query_results、cancel_live_queryCreateLiveQuery、GetLiveQuery、ListLiveQueryResults、CancelLiveQuery/v1/live-queries…
Monitoring subscriptionscreate_collection_subscription、list_collection_subscriptions、pause_…、resume_collection_subscription、list_collection_subscription_tasksCreateCollectionSubscription、ListCollectionSubscriptions、Pause…、ResumeCollectionSubscription、ListCollectionSubscriptionTasks/v1/collection/subscriptions…
Bulk exportscreate_export、get_export、list_export_files、download_export_file、cancel_exportCreateExport、GetExport、ListExportFiles、DownloadExportFile、CancelExport/v1/exports…
  • Pass mode="keyword" explicitly when searching. Vector-related fields left in the SDKs are retired.
  • Export downloads stream to disk rather than loading the whole file into memory.
  • Attachment download links are valid for 300 seconds; don’t send your API key when downloading.
  • For endpoints the SDKs don’t wrap, call the HTTP API with the same key.

Errors, retries and timeouts

  • On API errors, the SDKs raise or return APIError with code, message and the status (status in Python, Status in Go). Codes are listed in Error codes.
  • Only change feed methods retry automatically: network errors, 429 and 5xx, up to 3 attempts including the first. Other methods don’t retry.
  • Python times out after 30 seconds by default; change it with Client(timeout=...). In Go, the context you pass controls timeouts and cancellation.