This repository contains Beam client SDKs.
python/contains the existing Python package and CLI release inputs.go/contains the Go SDK module atgithub.com/beam-cloud/beam-client/go.js/contains the TypeScript/JavaScript SDK package@beamcloud/beam-js.
Run Go tests:
make test-goRun live Go sandbox integration tests against the local beta9 gateway:
make test-go-integrationThe integration target reads ~/.beta9/config.ini by default and requires a
local gateway (localhost, 127.0.0.1, or 0.0.0.0, which the harness maps
to loopback). It will fail before
creating any sandbox if the resolved gateway is gateway.beam.cloud or staging.
Use BEAM_TOKEN, BEAM_GATEWAY_HOST, and BEAM_GATEWAY_PORT or the matching
BETA9_* variables to point at a specific local setup. For a local token that
is not the default context, run:
BEAM_TOKEN=... make test-go-integrationRun runtime-specific integration targets:
make test-go-integration-runc
make test-go-integration-gvisorThe runc target uses the scheduler default pool. The gVisor target defaults
BEAM_TEST_POOL to gvisor; set BEAM_TEST_POOL=... to override the pool name
used by sandbox creation.
Run the optional Docker sandbox smoke on the gVisor pool:
make test-go-integration-dockerRun Python tests:
cd python && poetry run pytestRun JS tests:
make test-jsBuild the JS package:
make build-jsBuild the Python CLI wheel:
cd python && poetry build -f wheelPublish the Python package to PyPI:
POETRY_PYPI_TOKEN_PYPI=... make publish-pythonPublish the JS package to npm after npm login:
make publish-jsThe Go module is github.com/beam-cloud/beam-client/go.
Install:
go get github.com/beam-cloud/beam-client/go@latestPin a release:
go get github.com/beam-cloud/beam-client/go@v0.1.0Import:
import beam "github.com/beam-cloud/beam-client/go"For production, set BEAM_TOKEN and call beam.NewClient(ctx). The SDK
defaults to Beam's production gateway at gateway.beam.cloud:443.
export BEAM_TOKEN=...beam.NewClient(ctx) resolves configuration in this order:
- Explicit options such as
beam.WithTokenandbeam.WithGateway. BEAM_TOKEN,BEAM_GATEWAY_HOST,BEAM_GATEWAY_PORT.BETA9_TOKEN,BETA9_GATEWAY_HOST,BETA9_GATEWAY_PORT.~/.beam/config.inior~/.beta9/config.ini.gateway.beam.cloud:443.
For development against a local beta9 gateway, override the gateway:
export BEAM_TOKEN=...
export BEAM_GATEWAY_HOST=127.0.0.1
export BEAM_GATEWAY_PORT=1993Set SandboxConfig.Name to the app name that groups related sandboxes. Each
created sandbox still has a generated container ID, available from
sandbox.SandboxID().
ctx := context.Background()
client, err := beam.NewClient(ctx)
if err != nil {
return err
}
defer client.Close()
sandbox, err := client.CreateSandbox(ctx, beam.SandboxConfig{
Name: "example",
Image: beam.NewImage(beam.WithPythonVersion("python3.11")),
})
if err != nil {
return err
}
defer sandbox.Terminate(context.Background())
result, err := sandbox.RunCode(ctx, "print('hello from Beam')", beam.ExecOptions{})
if err != nil {
return err
}
fmt.Print(result.Stdout)Use sandbox.Status, sandbox.Poll, and sandbox.Wait when you need to
observe sandbox lifecycle state. CreateSandbox waits for the sandbox to be
ready before returning.
Use Exec for argv-safe command execution and ExecShell when you intentionally
want shell text sent as-is. Process stdout and stderr reads are consumptive
server deltas, so use Process.Output for a completed result or Process.Stream
for live logs.
proc, err := sandbox.Exec(ctx, []string{"sh", "-lc", "echo out; echo err >&2"}, beam.ExecOptions{})
if err != nil {
return err
}
exitCode, err := proc.Stream(ctx, func(entry beam.LogEntry) {
fmt.Print(entry.Data)
})Sandbox filesystem APIs are available through sandbox.FS. Beam volumes and
cloud buckets are configured with beam.NewVolume and beam.NewCloudBucket.
Secrets and GPUs are configured directly on SandboxConfig.
sandbox, err := client.CreateSandbox(ctx, beam.SandboxConfig{
Name: "resources-example",
Image: beam.NewImage(beam.WithPythonVersion("python3.11")),
GPU: "T4",
GPUCount: 1,
Secrets: []string{"MY_SECRET"},
Volumes: []beam.VolumeMount{
beam.NewVolume("cache", "/mnt/cache"),
beam.NewCloudBucket("/mnt/bucket", beam.CloudBucketConfig{
BucketName: "my-bucket",
Region: "us-east-1",
ReadOnly: true,
}),
},
})Docker-in-Docker requires both Image.WithDocker() and
SandboxConfig.DockerEnabled. Docker helpers default inner containers and
Compose services to host networking/PID mode so they work under both runc and
gVisor sandbox runtimes.
sandbox, err := client.CreateSandbox(ctx, beam.SandboxConfig{
Name: "docker-example",
Image: beam.NewImage(beam.WithPythonVersion("python3.11")).WithDocker(),
DockerEnabled: true,
})
if err != nil {
return err
}
proc, err := sandbox.Docker.Run(ctx, "busybox:1.36", beam.DockerRunOptions{
Remove: true,
Command: []string{"sh", "-c", "echo hello"},
})Use SnapshotMemory to checkpoint a sandbox and
CreateSandboxFromMemorySnapshot to restore it:
checkpointID, err := sandbox.SnapshotMemory(ctx)
restored, err := client.CreateSandboxFromMemorySnapshot(ctx, checkpointID)Runnable sandbox examples live in go/examples:
cd go
export BEAM_TOKEN=...
go run ./examples/basic
go run ./examples/filesystem
go run ./examples/http
go run ./examples/snapshot
go run ./examples/docker
go run ./examples/resourcesPython CLI: create a GitHub release named cli-X.Y.Z. release-cli.yml builds
the wheel from python/ and embeds it in the platform CLI binaries with PyApp.
Go SDK: tag the go/ submodule as go/vX.Y.Z:
git tag go/v0.1.0
git push origin go/v0.1.0Go users request the module version without the subdirectory prefix:
go get github.com/beam-cloud/beam-client/go@v0.1.0release-go.yml checks the tag shape, runs Go tests, and verifies that a fresh
module can fetch and import github.com/beam-cloud/beam-client/go from GitHub.
The Go SDK publishes through the Git tag; it has no binary artifact.
JavaScript SDK: create a GitHub release or tag named js/vX.Y.Z:
git tag js/v1.2.3
git push origin js/v1.2.3release-js.yml installs dependencies in js/, sets the package version from
the tag, runs tests, builds the package, and publishes @beamcloud/beam-js to
npm. Prereleases publish under the rc npm tag.