---
title: SDKs
description: Use Spacefolder from TypeScript, JavaScript, or Python.
seo:
  description: "Install and configure the Spacefolder TypeScript and Python SDKs to create Worlds, Fold events, Navigate outcomes, and read run history."
---

The SDKs are thin HTTP clients for the same API. They read `SPACEFOLDER_API_KEY` and connect to the hosted API automatically; you do not need to configure a URL.

Registry installation becomes available after the first package releases. Until then, use the source installation commands below from a checkout of this repository.

## TypeScript and JavaScript

Node.js 22 or newer:

```sh
npm install @spacefolder/sdk
```

```ts
import { SpacefolderClient, SpacefolderApiError } from "@spacefolder/sdk";

const sf = new SpacefolderClient();
await sf.createWorld({ id: "my_app", name: "My application" });
await sf.fold({
  world_id: "my_app",
  events: [{
    id: "view-001",
    name: "movie_viewed",
    timestamp: new Date().toISOString(),
    entity_id: "user_123",
    data: {},
  }],
});
const navigation = await sf.navigate({
  nav_id: "watch_after_impression",
  world_id: "my_app",
  context: {
    task: {
      history: [{ name: "movie_impression", data: { movie_id: "movie_456" } }],
    },
  },
  entity_id: "user_123",
  predictions: {
    watch: { event: "movie_watched", horizon: "1h" },
  },
});
const watch = navigation.predictions?.watch;
const confidence = watch && "confidence" in watch ? watch.confidence : null;
console.log(confidence ?? "Confidence unavailable");
```

Explicit configuration uses milliseconds for `timeout`:

```ts
const sf = new SpacefolderClient({
  apiKey: process.env.SPACEFOLDER_API_KEY,
  timeout: 30_000,
});
```

Keep API keys on your server. Browser applications should call your server, which uses the SDK to reach Spacefolder.

A rejected HTTP response throws `SpacefolderApiError`, with `status` and `payload`. Network failures and timeouts throw transport errors. Requests do not automatically retry or follow redirects.

## Python

Python 3.11 or newer; the SDK requires `jsonschema` and does not install Torch or model weights:

```sh
pip install spacefolder-sdk
```

```python
from datetime import datetime, timezone
from spacefolder_sdk import SpacefolderClient, SpacefolderApiError

sf = SpacefolderClient()
sf.create_world("my_app", name="My application")
sf.fold({
    "world_id": "my_app",
    "events": [{
        "id": "view-001",
        "name": "movie_viewed",
        "timestamp": datetime.now(timezone.utc).isoformat(),
        "entity_id": "user_123",
        "data": {},
    }],
})
navigation = sf.navigate({
    "nav_id": "watch_after_impression",
    "world_id": "my_app",
    "context": {
        "task": {
            "history": [{"name": "movie_impression", "data": {"movie_id": "movie_456"}}],
        },
    },
    "entity_id": "user_123",
    "predictions": {
        "watch": {"event": "movie_watched", "horizon": "1h"},
    },
})
confidence = navigation.get("predictions", {}).get("watch", {}).get("confidence")
print(confidence if confidence is not None else "Confidence unavailable")
```

Explicit configuration uses seconds for `timeout`:

```python
sf = SpacefolderClient(
    api_key="your-workspace-api-key",
    timeout=30,
)
```

HTTP rejections raise `SpacefolderApiError`, with `status` and `payload`. Schema validation errors are `jsonschema.ValidationError`. Network failures use standard library exceptions. Set `api_key=""` to disable environment authentication. Requests do not automatically retry or follow redirects.

Every Navigate request requires a `context` object with decision-time user or task information. Pass `context: {}` in TypeScript or `"context": {}` in Python when none is available.

For [context](/docs/concepts/primitives#context), prediction, action, and objective payloads, see [Navigate](/docs/concepts/primitives#navigate) and the [Navigate endpoint](/docs/reference/api/navigate/navigate).

## Forecast confidence

Both SDKs return the API's [forecast confidence](/docs/concepts/primitives#confidence) alongside the estimate. For comparisons, read the same field under `actions.<action>.predictions.<name>`. Check for an absent or null score and preserve `0`. Use `navigation(run_id)` to retrieve the original score and the latest verification.

## Methods

| Operation | TypeScript | Python |
| --- | --- | --- |
| Create World | `createWorld(request)` | `create_world(world_id, name=None)` |
| Get World | `world(id)` | `world(world_id)` |
| List Worlds | `worlds({ cursor, limit })` | `worlds(cursor=None, limit=100)` |
| Rename World | `renameWorld(id, { name })` | `rename_world(world_id, name)` |
| Delete World | `deleteWorld(id, { confirm_id })` | `delete_world(world_id, confirm_id)` |
| Fold events | `fold(request)` | `fold(request)` |
| Navigate | `navigate(request)` | `navigate(request)` |
| Fold history | `folds(world_id, filters)` | `folds(world_id, **filters)` |
| Navigate history | `navigations(world_id, filters)` | `navigations(world_id, **filters)` |
| Fold detail | `foldDetail(world_id, run_id)` | `fold_detail(world_id, run_id)` |
| Get forecast and verification | `navigation(run_id)` | `navigation(run_id)` |
| Include the execution trace | `navigation(run_id, { trace: true })` | `navigation(run_id, trace=True)` |

Pass `next_cursor` as `cursor` to read the next page of Worlds, Folds, or navigations. Filter names match the [API reference](/docs/reference/api).

## Install from source

Run in the repository root:

```sh
npm ci
npm run build:sdk
npm pack --workspace @spacefolder/sdk
# Install the resulting .tgz in your application.

python -m pip install ./sdk/python
```

The Python SDK and the repository's internal `spacefolder-reference` package both contain the `spacefolder_sdk` namespace. Install the public SDK in a separate environment from the reference/model package.
