Official client libraries for the Codewire API.
| Language | Package | Status |
|---|---|---|
| TypeScript | @codewire/sdk |
Alpha |
| Go | codewire.sh/sdk-go |
Alpha |
| Python | codewire |
Alpha |
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()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();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)The SDK is built around the environment as the primary object. The typical flow:
- Create --
create()returns anEnvironmentwith methods bound to it. - Wait -- pass
wait=Trueto block until the environment is running, or callwait_ready()/WaitReady()separately. - Exec -- run commands via
env.exec(...). - Files -- transfer files via
env.files.*. - 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 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
env.files.upload(b"input data", "/workspace/input.txt")
entries = env.files.list("/workspace")
content = env.files.download("/workspace/output.txt")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");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")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
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_..."))Types are generated from the server's OpenAPI spec:
cd sdk && make generate # Regenerate all types
cd sdk && make check # Verify everything compilesMIT