Skip to content

codewiresh/sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codewire SDK

Official client libraries for the Codewire API.

Language Package Status
TypeScript @codewire/sdk Alpha
Go codewire.sh/sdk-go Alpha
Python codewire Alpha

Quick start

Python

from codewire import Codewire

cw = Codewire()

env = cw.environments.create(template_slug="python", wait=True)
result = env.exec(command=["python3", "-c", "print('hello')"])
print(result["stdout"])
env.remove()

TypeScript

import { Codewire } from "@codewire/sdk";

const cw = new Codewire();

const env = await cw.environments.create(
  { template_slug: "python" },
  { wait: true },
);
const result = await env.exec({ command: ["python3", "-c", "print('hello')"] });
console.log(result.stdout);
await env.remove();

Go

import codewire "codewire.sh/sdk-go"

client := codewire.New("")

env, err := client.Environments.Create(ctx, api.CreateEnvironmentBody{
    TemplateSlug: ptr("python"),
}, codewire.CreateOptions{Wait: true})
result, err := env.Exec(ctx, api.ExecBody{
    Command: &[]string{"python3", "-c", "print('hello')"},
})
fmt.Println(result.Stdout)
env.Remove(ctx)

Environment lifecycle

The SDK is built around the environment as the primary object. The typical flow:

  1. Create -- create() returns an Environment with methods bound to it.
  2. Wait -- pass wait=True to block until the environment is running, or call wait_ready() / WaitReady() separately.
  3. Exec -- run commands via env.exec(...).
  4. Files -- transfer files via env.files.*.
  5. Cleanup -- destroy with env.remove().

Environment methods:

env.exec(...)         # Execute a command
env.start()           # Start a stopped environment
env.stop()            # Stop a running environment
env.remove()          # Delete the environment
env.wait_ready()      # Poll until state is "running"
env.list_ports()      # List exposed ports
env.create_port(...)  # Expose a port
env.delete_port(...)  # Remove a port

File operations

File operations live under env.files:

env.files.list(path)              # List files at path
env.files.upload(data, path)      # Upload a file
env.files.download(path)          # Download a file

Python

env.files.upload(b"input data", "/workspace/input.txt")
entries = env.files.list("/workspace")
content = env.files.download("/workspace/output.txt")

TypeScript

await env.files.upload(new TextEncoder().encode("input data"), "/workspace/input.txt");
const entries = await env.files.list("/workspace");
const buf = await env.files.download("/workspace/output.txt");

Go

env.Files.Upload(ctx, strings.NewReader("input data"), "/workspace/input.txt")
entries, _ := env.Files.List(ctx, ptr("/workspace"))
body, _ := env.Files.Download(ctx, "/workspace/output.txt")

Services

All SDKs provide these services:

  • Environments -- create, list, get, delete, start, stop, exec, files, ports
  • Templates -- create, list, get, update, delete
  • API Keys -- create, list, delete
  • Secrets -- list, set, delete (org + user scopes)
  • Secret Projects -- create, list, delete, manage project secrets

Authentication

Set credentials via environment variables:

CODEWIRE_API_KEY=cw_...
CODEWIRE_ORG_ID=org_...

Or pass them to the client constructor:

cw = Codewire(api_key="cw_...", org_id="org_...")
const cw = new Codewire({ apiKey: "cw_...", orgId: "org_..." });
client := codewire.New("cw_...", codewire.WithOrgID("org_..."))

Codegen

Types are generated from the server's OpenAPI spec:

cd sdk && make generate  # Regenerate all types
cd sdk && make check     # Verify everything compiles

License

MIT

About

Codewire SDK — Go, Python, and TypeScript clients for the Codewire API

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors