SDKs
Official client libraries for Go, Python, TypeScript, PHP, and .NET.
Overview
Official SDKs are available for five languages. Each SDK wraps the REST API and provides real-time streaming via Server-Sent Events (SSE).
All SDKs are open source and generated from the OpenAPI spec.
| Language | Package | Install |
|---|---|---|
| Go | sawvant-go | go get github.com/sawvant/sawvant-go |
| Python | sawvant | pip install sawvant |
| TypeScript | @sawvant/sdk | npm install @sawvant/sdk |
| PHP | sawvant/sdk | composer require sawvant/sdk |
| .NET | Sawvant | dotnet add package Sawvant |
Quick Start
Go
cfg := sawvant.NewConfiguration()
cfg.Host = "api.sawvant.com"
ctx := context.WithValue(context.Background(), sawvant.ContextAPIKeys, map[string]sawvant.APIKey{
"ApiKeyAuth": {Key: "sk_your_api_key"},
})
client := sawvant.NewAPIClient(cfg)
job, _, err := client.OptimizeApi.CreateOptimization(ctx).OptimizeRequest(sawvant.OptimizeRequest{
Sheets: []sawvant.Sheet{{Width: 2440, Height: 1220, Quantity: 5}},
Parts: []sawvant.Part{{Width: 600, Height: 400, Quantity: 10, Label: sawvant.PtrString("Panel A")}},
}).Execute()Python
import sawvant
from sawvant.api import optimize_api
from sawvant.model.optimize_request import OptimizeRequest
from sawvant.model.sheet import Sheet
from sawvant.model.part import Part
configuration = sawvant.Configuration(
host='https://api.sawvant.com',
api_key={'ApiKeyAuth': 'sk_your_api_key'},
)
with sawvant.ApiClient(configuration) as client:
api = optimize_api.OptimizeApi(client)
job = api.create_optimization(optimize_request=OptimizeRequest(
sheets=[Sheet(width=2440, height=1220, quantity=5)],
parts=[Part(width=600, height=400, quantity=10, label='Panel A')],
))TypeScript
import { OptimizeApi, Configuration } from '@sawvant/sdk';
const api = new OptimizeApi(new Configuration({
apiKey: 'sk_your_api_key',
basePath: 'https://api.sawvant.com',
}));
const job = await api.createOptimization({
optimizeRequest: {
sheets: [{ width: 2440, height: 1220, quantity: 5 }],
parts: [{ width: 600, height: 400, quantity: 10, label: 'Panel A' }],
},
});PHP
$config = new Configuration();
$config->setHost('https://api.sawvant.com');
$config->setApiKey('ApiKeyAuth', 'sk_your_api_key');
$client = new ApiClient($config);
$api = new OptimizeApi($client);
$job = $api->createOptimization(new OptimizeRequest([
'sheets' => [new Sheet(['width' => 2440, 'height' => 1220, 'quantity' => 5])],
'parts' => [new Part(['width' => 600, 'height' => 400, 'quantity' => 10, 'label' => 'Panel A'])],
]));.NET
using Sawvant;
var config = new Configuration { ApiKey = "sk_your_api_key" };
var api = new OptimizeApi(config);
var job = await api.CreateOptimizationAsync(new OptimizeRequest
{
Sheets = new List<Sheet> { new() { Width = 2440, Height = 1220, Quantity = 5 } },
Parts = new List<Part> { new() { Width = 600, Height = 400, Quantity = 10, Label = "Panel A" } },
});SSE Streaming
All SDKs support real-time job progress via Server-Sent Events. The streaming interface varies per language but follows the same pattern: subscribe to events, receive progress updates, and get the final result on completion.
How it works
SSE events emitted by the server intentionally omit the full optimization result to keep payloads small. When the SDK receives a completed event, it automatically fetches the full result via GET /v1/jobs/{id} and includes it in the event data. This happens transparently — you always receive the complete result.
Go
events, errs := client.StreamJob(ctx, jobID)
for {
select {
case event, ok := <-events:
if !ok {
return
}
switch event.Type {
case "progress":
fmt.Printf("Progress: %d%%\n", event.Data.Progress)
case "completed":
fmt.Printf("Done: %v\n", event.Data.GetResult())
return
case "failed":
log.Fatalf("Failed: %s", event.Data.GetError())
}
case err := <-errs:
if err != nil {
log.Fatal(err)
}
}
}Python
from sawvant.streaming import stream_job
for event in stream_job(job.id, api_key='sk_your_api_key'):
if event.type == 'progress':
print('Progress:', event.data)
elif event.type == 'completed':
print('Done:', event.data)
break
elif event.type == 'failed':
print('Failed:', event.data)
breakTypeScript
import { streamJob } from '@sawvant/sdk';
for await (const event of streamJob(job.id, { apiKey: 'sk_your_api_key' })) {
if (event.type === 'completed') {
console.log('Done:', event.data);
break;
}
}PHP
foreach ($jobsApi->streamJob($job->getId()) as $event) {
match ($event->getType()) {
'progress' => print('Progress: ' . $event->getData() . PHP_EOL),
'completed' => print('Done: ' . $event->getData() . PHP_EOL),
'failed' => throw new \RuntimeException('Job failed'),
};
if (in_array($event->getType(), ['completed', 'failed'])) {
break;
}
}.NET
await foreach (var evt in Streaming.StreamJobAsync(jobId, apiKey))
{
Console.WriteLine($"{evt.Type}: progress={evt.Data.Progress}%");
if (evt.Type == "completed")
{
var result = evt.Data.Result;
}
}API Methods
All SDKs expose the same four endpoints:
| Method | HTTP | Path | Description |
|---|---|---|---|
| Create Optimization | POST | /v1/optimize | Submit a cutting optimization job |
| Get Job | GET | /v1/jobs/{id} | Retrieve job status and result |
| Stream Job | GET | /v1/jobs/{id}/stream | Stream job progress via SSE |
| Health Check | GET | /health | Health check (no auth required) |
Requirements
| SDK | Minimum Version |
|---|---|
| Go | Go 1.21+ |
| Python | Python 3.8+ |
| TypeScript | Node.js 18+ |
| PHP | PHP 8.1+ |
| .NET | .NET 6.0+ |