SDK
JavaScript, TypeScript and Python clients: pagination, demo downloads and live recovery.
JavaScript / TypeScript
The repository produces a standalone @scoreriver/sdk npm tarball and a scoreriver-sdk Python wheel/sdist. They are release candidates, not yet published to registries. Install the provided artifacts; Node.js 22+ or Python 3.11+ is required. Keep service API keys on the backend. Requests validate parameters before sending. Responses validate known fields and invariants while ignoring additional object fields. Unknown enum values and missing required data still fail validation.
import { createScoreRiverClient, ScoreRiverApiError } from '@scoreriver/sdk';
const api = createScoreRiverClient({ baseUrl, apiKey });
try {
const page = await api.listMatches({ limit: 10 });
// Continue with the same filters and page.page.nextCursor.
} catch (error) {
if (error instanceof ScoreRiverApiError) {
// status, code, retryAfterSeconds, issues: [{ path, code, message }]
// Retry only transient failures, with a bounded policy.
} else throw error;
}Walk every page
JS/TS paginatePages/paginateItems and Python pages/items preserve filters and the publication snapshot. They fetch lazily and reject cursor loops. They apply to top-level lists; nested statistics groups and change feeds have separate cursors.
import { paginateItems } from '@scoreriver/sdk';
for await (const player of paginateItems(api.listPlayers, { limit: 100 })) {
console.log(player.id, player.nickname);
}Python: synchronous and async
Install: python -m pip install ./scoreriver_sdk-0.1.0-py3-none-any.whl. Methods and response attributes use snake_case; query dictionary keys retain camelCase. AsyncScoreRiver has the same methods with await and async iteration. Response models validate known data; IDs and dates remain strings.
import os
from scoreriver import ScoreRiver
with ScoreRiver(
base_url=os.environ['SCORERIVER_API_URL'],
api_key=os.environ['SCORERIVER_API_KEY'],
) as api:
for player in api.items(api.list_players, {'limit': 100}):
print(player.id, player.nickname)Stream DEM files
matchRecordings(matchId) lists available files. downloadRecording(matchId, recordingId, { range, signal }) returns a standard streaming Response and the same structured HTTP errors. Pass an AbortSignal for cancellation. Automatic retries are not performed; respect retryAfterSeconds and avoid retrying invalid requests.
Python DEM streams
The context closes the response on completion or failure. Async clients support async with and response.aiter_bytes(). For resume, pass byte_range and verify HTTP 206 / Content-Range before appending. Compare the complete file with its SHA-256 metadata.
with api.download_recording(match_id, recording_id) as response:
with open('match.dem', 'xb') as output:
for chunk in response.iter_bytes():
output.write(chunk)Live delivery and recovery
JS/TS createScoreRiverLiveClient uses Socket.IO: callbacks finish before acknowledgment and reconnect resumes the handled sequence. Python api.live uses SSE: process a yielded message before advancing iteration; reconnect sends Last-Event-ID. Persist checkpoints and apply events idempotently. Expired history or a gap requires a fresh snapshot. Python supports sync/async SSE; NATS helpers are currently JS/TS only.
from contextlib import closing
with closing(api.live(match_id, after_sequence=None)) as events:
for message in events:
apply_message(message) # save sequence after successful processingErrors and cancellation
JS/TS ScoreRiverApiError and Python ScoreRiverAPIError expose status, code, issues and Retry-After (retryAfterSeconds / retry_after_seconds). REST calls are not automatically retried. Correct 400/401/403/404 errors; retry only transient failures with a bounded policy. JS combines AbortSignal with its deadline. Python uses HTTPX I/O timeouts; async task cancellation closes the active stream. Python live retries are bounded and authentication/validation errors are terminal.
Optional NATS backend delivery
NATS access is provisioned separately for an application ID and NKey bound to an active API access. A REST API key alone cannot connect to the broker. Keep seeds on the backend. The SDK realtime entry point offers connectRealtime and createRealtimeQueryClient. read() uses the same operation registry and published projections; watch() delivers full replacement views under a renewable lease. Do not treat a view as a durable event log.
Requests are bounded to 32 KiB and responses to 1 MiB. Authorization and account quotas are shared with HTTP. A revoked or rotated credential invalidates the binding. Close watches on disposal; reconnect by obtaining a new snapshot. Immutable publication/live events use the separately provisioned JetStream consumer; acknowledge only after durable processing and deduplicate event IDs.