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
- Download the Go SDK, unpack it, and run
go test ./...in the package directory. - 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- 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"])
}
}- Run
go mod tidy, thengo 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
| Use | Python | Go | Endpoint |
|---|---|---|---|
| Search | search | Search | POST /v1/search |
| Search stored data only | search_history | SearchHistory | POST /v1/search/history |
| Browse by filters | browse_documents | BrowseDocuments | GET /v1/documents/browse |
| User profile | get_user | GetUser | GET /v1/users/{platform}/{id} |
| A user’s documents | list_user_documents | ListUserDocuments | GET /v1/users/{platform}/{id}/documents |
| Category dictionary | list_classifications | ListClassifications | GET /v1/classifications |
| Document metadata | get_document | GetDocument | GET /v1/documents/{id} |
| Full body | get_document_content | GetDocumentContent | GET /v1/documents/{id}/content |
| Batch read | batch_get | BatchGet | POST /v1/documents/batch-get |
| Version history | list_document_versions | ListDocumentVersions | GET /v1/documents/{id}/versions |
| Metric snapshots | list_document_snapshots | ListDocumentSnapshots | GET /v1/documents/{id}/snapshots |
| Subtitles, OCR and other parts | list_document_parts | ListDocumentParts | GET /v1/documents/{id}/parts |
| Facts | list_document_facts | ListDocumentFacts | GET /v1/documents/{id}/facts |
| Attachments and download links | list_attachments、get_attachment_download_url | ListAttachments、GetAttachmentDownloadURL | GET /v1/documents/{id}/attachments… |
| Change feed | list_changes、iter_change_pages | ListChanges、NewChangesIterator | GET /v1/changes |
| Live queries | create_live_query、get_live_query、list_live_query_results、cancel_live_query | CreateLiveQuery、GetLiveQuery、ListLiveQueryResults、CancelLiveQuery | /v1/live-queries… |
| Monitoring subscriptions | create_collection_subscription、list_collection_subscriptions、pause_…、resume_collection_subscription、list_collection_subscription_tasks | CreateCollectionSubscription、ListCollectionSubscriptions、Pause…、ResumeCollectionSubscription、ListCollectionSubscriptionTasks | /v1/collection/subscriptions… |
| Bulk exports | create_export、get_export、list_export_files、download_export_file、cancel_export | CreateExport、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
APIErrorwithcode,messageand the status (statusin Python,Statusin Go). Codes are listed in Error codes. - Only change feed methods retry automatically: network errors,
429and5xx, 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, thecontextyou pass controls timeouts and cancellation.