Python SDK for Sprites
- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
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> |
||
| .github/workflows | ||
| examples | ||
| src/sprites | ||
| test_cli | ||
| tests | ||
| .gitignore | ||
| pyproject.toml | ||
| README.md | ||
| test-cli | ||
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