SDKs
TypeScript, Python, Go and Rust clients that pass one shared test suite. Paths instead of ids, streaming uploads and ranged downloads, safe writes, edits, sidecars, search, changes and webhooks.
這一頁還沒有翻譯,所以先以英文顯示。
| Language | Package | Folder | Runs on |
|---|---|---|---|
| TypeScript / JavaScript | @sidespace/sdk | sdks/typescript | Node 18+, Deno, Bun, browsers (anything with fetch) |
| Python | sidespace | sdks/python | Python 3.9+, standard library only |
| Go | github.com/blendduck/sidespace/sdks/go | sdks/go | Go 1.22+, standard library only |
| Rust | sidespace | sdks/rust | Async, on reqwest (rustls) and tokio |
All four are Apache-2.0 and cover the same ground for files. They are not on npm, PyPI, the Go module proxy or crates.io yet: use them from a checkout of the repository, or copy the folder into your project.
npm install ./sdks/typescriptpip install ./sdks/python# in your module, point the import at the checkout
go mod edit -replace github.com/blendduck/sidespace/sdks/go=../sidespace/sdks/go
go get github.com/blendduck/sidespace/sdks/go# Cargo.toml
[dependencies]
sidespace = { path = "../sidespace/sdks/rust" }Set up
import { SideSpace } from "@sidespace/sdk";
const side = new SideSpace({ baseUrl: "https://side.space", token: process.env.SIDESPACE_TOKEN! });
await side.upload("/Ep01/notes.md", "# Notes\n"); // in the drive the token is made forfrom sidespace import SideSpace
side = SideSpace("https://side.space", token="ssp_…") # or SideSpace() with SIDESPACE_URL and SIDESPACE_TOKEN set
side.upload("/Ep01/notes.md", "# Notes\n") # in the drive the token is made forimport sidespace "github.com/blendduck/sidespace/sdks/go"
side := sidespace.New("https://side.space", os.Getenv("SIDESPACE_TOKEN"))
saved, err := side.UploadText(ctx, "/Ep01/notes.md", "# Notes\n", nil) // in the drive the token is made foruse sidespace::SideSpace;
let side = SideSpace::new("https://side.space", &std::env::var("SIDESPACE_TOKEN")?);
let saved = side.upload_text("/Ep01/notes.md", "# Notes\n", &Default::default()).await?; // in the token's driveA token made for one drive has the client work in it, so calls take only paths. For a token that reaches several drives (a whole workspace, say), side.space("Film A") (side.Space("Film A") in Go) gives a client for one of them, by name (any case) or id; without it, calls answer space_required. search looks in every drive the token reaches, or only in the one named. Errors carry the server's status, code and message: SideSpaceError in TypeScript and Python, and in Go and Rust an error with IsPreconditionFailed / is_precondition_failed() and the current version for a safe write that lost. Each folder's README has the full method list.
What's covered
| Area | TypeScript | Python |
|---|---|---|
| Drives and folders | space(), spaceInfo(), spaces(), node(), list(), mkdir() | space(), space_info(), spaces(), node(), list(), mkdir() |
| Upload and download | upload(), download(), open() with range | upload() (streams file objects), download(), open() with range |
| Versions | versions(), restoreVersion() | versions(), restore_version() |
| Part of a file | edit(), appendText() | edit(), append_text() |
| The past | asOf on node(), list(), open(), download(); rewind() | as_of= on node(), list(), open(); rewind() |
| Sidecars | getSidecar(), putSidecar() | get_sidecar(), put_sidecar() |
| Search | search(q, { type, mode }) | search(q, type=, mode=) |
| Changes | journal(), changes() (async iterator) | journal(), changes() (generator) |
| Webhooks | createWebhook(), verifyWebhookSignature() from @sidespace/sdk/webhooks | create_webhook(), verify_webhook_signature() |
| Comments | comments(), addComment(), editComment(), resolveComment() | comments(), add_comment(), edit_comment(), resolve_comment() |
| Forks | fork(), forks(), forkChanges(), applyFork() | fork(), forks(), fork_changes(), apply_fork() |
Go and Rust cover the same file operations (drives, paths, streaming upload and ranged download, safe writes, byte-range edits, versions and guarded restore, the past and rewind, forks, sidecars, search, comments, changes and webhooks), with Go and Rust names (UploadText, ForkChanges, upload_text, fork_changes).
Anything else in the API reference is one request() away (Do in Go):
const presence = await side.request("GET", "/v1/space/presence"); // the token's drive
const film = await side.space("Film A").spaceInfo(); // or one named
const theirs = await side.request("GET", `/v1/spaces/${film.id}/presence`);presence = side.request("GET", "/v1/space/presence") # the token's drive
film = side.space("Film A").space_info() # or one named
theirs = side.request("GET", f"/v1/spaces/{film['id']}/presence")One test suite for all four
sdks/conformance/cases.json is one list of 48 steps (save, read ranges, safe-write conflicts, edits, guarded restore, version origins, forks, rewind, folders, sidecars, comments, search and errors) that every SDK runs against a live server, each through its own runner. check.py compares their answers, so the four SDKs can't drift apart. All four pass. To check one yourself against a dev server:
SIDESPACE_SERVER=… SIDE_TOKEN=… SPACE=… python3 sdks/conformance/runner.py | python3 sdks/conformance/check.py --sdk pythonA new SDK, in any language, is done when it passes every step.
A complete example
Score every clip in /dailies that hasn't been scored yet with your own model, reading only the first 8 MB of each, and keep the result in a sidecar:
import { SideSpace, SideSpaceError } from "@sidespace/sdk";
const side = new SideSpace({ baseUrl: process.env.SIDESPACE_URL!, token: process.env.SIDESPACE_TOKEN! });
for (const file of await side.list("/dailies")) {
if (!file.mime?.startsWith("video/")) continue;
const path = `/dailies/${file.name}`;
const done = await side.getSidecar(path, "x-mymodel").catch((e) => {
if (e instanceof SideSpaceError && e.status === 404) return null;
throw e;
});
if (done) continue;
const head = await side.open(path, { range: [0, 8 * 1024 * 1024 - 1] });
const score = await myModel(await head.arrayBuffer());
await side.putSidecar(path, "x-mymodel", { score, model: "mymodel-2" });
}from sidespace import SideSpace, SideSpaceError
side = SideSpace()
for file in side.list("/dailies"):
if not (file.get("mime") or "").startswith("video/"):
continue
path = f"/dailies/{file['name']}"
try:
side.get_sidecar(path, "x-mymodel")
continue # already scored
except SideSpaceError as e:
if e.status != 404:
raise
with side.open(path, range=(0, 8 * 1024 * 1024 - 1)) as r:
score = my_model(r.read())
side.put_sidecar(path, "x-mymodel", {"score": score, "model": "mymodel-2"})To keep up with new clips as they land, run the same code from a webhook: it keeps its place and retries for you.