Sdk
Cross-SDK Parity
Feature matrix and API comparison across Python, TypeScript, and Go SDKs.
Sluice SDK -- Cross-SDK Parity
API comparison
| Operation | Python | TypeScript | Go |
|---|---|---|---|
| Preferred API | async with slot(dim, timeout) | await slot(dim, { timeout }) | WithSlot(ctx, dim, timeout, fn) |
| Preferred multi | async with slot_many(dims, timeout) | await slotMany(dims, { timeout }) | WithSlotMany(ctx, dims, timeout, fn) |
| Handle API | N/A (context manager is the handle) | slot() returns SlotHandle | Slot() returns *SlotHandle |
| Low-level acquire | await acquire(dim, config?) | await acquire(dim, config?) | Acquire(ctx, dim, ...opts) |
| Low-level multi | await acquire_many(dims, config?) | await acquireMany(dims, config?) | AcquireMany(ctx, dims, ...opts) |
| Release | await result.release() | await result.release() | result.Release(ctx) |
| Penalize | await penalize(dim, factor?, config?) | await penalize(dim, factor?, config?) | Penalize(ctx, dim, factor, ...opts) |
| Config constructor | SluiceConfig(...) | new SluiceConfig({...}) | sluice.Config{...} |
| Config from env | SluiceConfig.from_env() | SluiceConfig.fromEnv() | ConfigFromEnv() |
| Config injection | config= parameter | config in options or parameter | WithConfig(cfg) option |
| Client (conn reuse) | async with SluiceClient() as c | new SluiceClient() / c.destroy() | sluice.NewClient(ctx) |
Outcome values
| Python | TypeScript | Go |
|---|---|---|
AcquireOutcome.GRANTED | AcquireOutcome.Granted | sluice.Granted |
AcquireOutcome.RETRY_IN | AcquireOutcome.RetryIn | sluice.RetryIn |
Error types
| Error | Python | TypeScript | Go |
|---|---|---|---|
| Slot timeout | SlotTimeout (exception) | SlotTimeout (extends Error) | SlotTimeout (struct, implements error) |
| Missing dimension | Standard exception | Standard Error | *ConfigurationError |
Configuration environment variables
All three SDKs read the same environment variables with the same defaults:
| Variable | Default |
|---|---|
SLUICE_TABLE_NAME | "ontopix-vendor-buckets-prod" |
SLUICE_AWS_REGION | "eu-central-1" |
SLUICE_ENDPOINT_URL | Not set (standard AWS endpoint) |
SLUICE_LEASE_TTL | 60 (seconds) |
SLUICE_MAX_RETRIES | 3 |
SLUICE_DEFAULT_SLOT_TIMEOUT | 30.0 (seconds) |
SLUICE_LOG_LEVEL | "INFO" |
Language-idiomatic patterns
Python -- async context manager
The context manager handles acquire-retry-release automatically. The async with block guarantees release even if an exception is raised.
async with slot("openai#gpt-4o#requests", timeout=10.0) as result:
response = await call_openai(prompt)
TypeScript -- handle with try/finally
slot() returns a SlotHandle that must be released in a finally block. With TypeScript 5.2+, await using provides automatic disposal.
// Manual release
const handle = await slot("openai#gpt-4o#requests", { timeout: 10 });
try {
const response = await callOpenAI(prompt);
} finally {
await handle.release();
}
// Automatic disposal (TS 5.2+)
await using handle = await slot("openai#gpt-4o#requests", { timeout: 10 });
const response = await callOpenAI(prompt);
Go -- callback or defer
WithSlot is the safest because release is handled internally. Slot returns a handle that must be released with defer.
// Callback (recommended)
err := sluice.WithSlot(ctx, "openai#gpt-4o#requests", 10*time.Second,
func(ctx context.Context) error {
_, err := callOpenAI(ctx, prompt)
return err
},
)
// Handle + defer
handle, err := sluice.Slot(ctx, "openai#gpt-4o#requests", 10*time.Second)
if err != nil { return err }
defer handle.Release(ctx)
Common gotchas
Python
- All functions are
async. You mustawaitthem or useasync with. slot()is an async context manager, not a regular function that returns a handle. Do not try toawait slot(...)withoutasync with.penalizeis best-effort and does not raise on failure.
TypeScript
- All functions return promises. Do not forget
await. slot()returns aSlotHandle, not a context manager. You must callrelease()explicitly (or useawait using).penalizeis best-effort and silently swallows errors.- The
release()function onAcquireResultis idempotent -- calling it twice is safe.
Go
- All functions require a
context.Contextas the first argument, includingRelease. Penalizereturns an error (unlike Python/TS which swallow it). Check or explicitly discard with_ =.WithSlotinternally defers release, so the callback's context is the original context (not a derived one).- The
factorargument toPenalizeis required (not optional like in Python/TS). SlotTimeoutis a value type (SlotTimeout{}), not a pointer. Useerrors.As(err, &timeout)with a value variable.