Python SDK for Sprites
sdk
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jake Gaylor 808bbfa147
Drop close_timeout to 0 to match Elixir SDK behavior
The Elixir SDK (sprites-ex) sends a WS CLOSE frame and immediately
tears down the TCP connection on EXIT — it does not await the
server's reciprocal CLOSE handshake. Setting close_timeout=0 in
the Python websockets-lib client mirrors that: the CLOSE frame is
sent but `await ws.close()` returns immediately rather than waiting
for the server.

In a side-by-side bench (5 cat /tmp/x calls per warm sprite) this
should drop per-exec latency from ~650ms (with close_timeout=0.5)
to closer to the Elixir SDK's ~170ms.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 02:29:46 -04:00
.github/workflows Set up PyPI publishing as sprites-py (#4) 2026-01-10 00:28:56 -06:00
examples Fix service examples to use flat ServiceWithState attributes 2026-03-20 16:25:50 +00:00
src/sprites Drop close_timeout to 0 to match Elixir SDK behavior 2026-05-01 02:29:46 -04:00
test_cli Fix WebSocket timing for concurrent commands (#6) 2026-01-11 12:06:08 -06:00
tests Populate cmd.session_id from server's session_info on new exec sessions 2026-05-01 01:04:03 -04:00
.gitignore Initial Python SDK with examples 2026-01-07 14:04:11 +00:00
pyproject.toml Set up PyPI publishing as sprites-py (#4) 2026-01-10 00:28:56 -06:00
README.md Set up PyPI publishing as sprites-py (#4) 2026-01-10 00:28:56 -06:00
test-cli Initial Python SDK with examples 2026-01-07 14:04:11 +00:00

Sprites Python SDK

Python SDK for Sprites - remote command execution platform.

Installation

pip install sprites-py

Quick Start

from sprites import SpritesClient

# Create a client
client = SpritesClient(token="your-token")

# Get a sprite handle
sprite = client.sprite("my-sprite")

# Run a command
result = sprite.run("echo", "hello", capture_output=True)
print(result.stdout.decode())  # "hello\n"

# Or use the Go-style API
cmd = sprite.command("ls", "-la")
output = cmd.output()
print(output.decode())

API Overview

SpritesClient

from sprites import SpritesClient

client = SpritesClient(
    token="your-token",
    base_url="https://api.sprites.dev",  # optional
    timeout=30.0,  # optional
)

# Create a sprite
sprite = client.create_sprite("my-sprite")

# Get a sprite handle (doesn't create it)
sprite = client.sprite("my-sprite")

# Delete a sprite
client.delete_sprite("my-sprite")

Sprite

# Run a command (subprocess.run style)
result = sprite.run("echo", "hello", capture_output=True, timeout=30)
print(result.returncode)
print(result.stdout)

# Create a command (Go exec.Cmd style)
cmd = sprite.command("bash", "-c", "echo hello")
output = cmd.output()  # Returns stdout
combined = cmd.combined_output()  # Returns stdout + stderr

# TTY mode
cmd = sprite.command("bash", tty=True, tty_rows=24, tty_cols=80)
cmd.run()

Checkpoints

# List checkpoints
checkpoints = sprite.list_checkpoints()

# Create a checkpoint
stream = sprite.create_checkpoint("my checkpoint")
for msg in stream:
    print(msg.type, msg.data)

# Restore a checkpoint
stream = sprite.restore_checkpoint("checkpoint-id")
for msg in stream:
    print(msg.type, msg.data)

Network Policy

from sprites.types import NetworkPolicy, PolicyRule

# Get current policy
policy = sprite.get_network_policy()

# Update policy
new_policy = NetworkPolicy(rules=[
    PolicyRule(domain="example.com", action="allow"),
])
sprite.update_network_policy(new_policy)

Requirements

  • Python 3.11+
  • websockets
  • httpx

License

MIT