Metadata-Version: 2.4
Name: starfold
Version: 0.3.2
Summary: Python SDK for starfold
License-Expression: MIT
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: pillow>=10 ; extra == 'pillow'
Requires-Python: >=3.10
Project-URL: Repository, https://github.com/kyora-sh/starfold
Provides-Extra: pillow
Description-Content-Type: text/markdown

# starfold (Python)

A client for agents and scripts driving a starfold desktop: screenshots, waiting for the
screen, mouse and keyboard, recordings and files.

```sh
uv add starfold   # or: pip install starfold
```

From a checkout: `uv add --editable path/to/starfold/python/starfold` (or `pip install -e python/starfold`).

```python
from starfold import Starfold, act

# password defaults to $STARFOLD_PASSWORD
with Starfold("http://localhost:6901", password="...") as sf:
    shot = sf.screenshot()  # shot.png (bytes), shot.seq, shot.size
    shot.save("before.png")

    sf.click(400, 300)
    r = sf.type_text("hello\n")
    sf.wait(change=True, since=r.seq)  # returns once the typing changed the screen
    sf.wait(idle_ms=300)  # and once it settled

    sf.key("ctrl+shift+t")
    sf.scroll(dy=3, x=400, y=300)
    sf.drag(100, 100, 400, 100)
    sf.actions([act.key("ctrl+l"), act.type_text("example.com"), act.key("Enter")])

    clips = sf.record(5)  # a list of MP4s: one, or more if the encoder changed mid-recording
    sf.files_upload("data.csv", "local/data.csv")
    print([e.name for e in sf.files_list().entries])
```

`AsyncStarfold` has the same methods for asyncio. `Screenshot.image()` returns a Pillow
image if Pillow is installed (`starfold[pillow]`).

Errors: `AuthError` (wrong or missing password), `ReadOnlyError` (the server runs with
`--read-only`), `RecordingOffError` (it runs without `--enable-recording`), `ForbiddenError`,
`NotFoundError`, `StarfoldTimeoutError`, `StarfoldConnectionError`, and for the server on this
machine (below) `BinaryNotFoundError`, `MissingLibrariesError` and `ServerStartError`, all
`StarfoldError`. `wait()` reports a timeout in its result
(`timed_out`) rather than raising.

Keys for `key()` are a single character or a name (Enter, Tab, Escape, BackSpace, Delete,
Home, End, PageUp, PageDown, Up, Down, Left, Right, F1-F24, ...), joined with `+` after
modifiers (ctrl, shift, alt, altgr, super). With shift, a letter or a US-layout digit or
punctuation key means the shifted key: `ctrl+shift+t`, `cmd+shift+4`.

## The server, from the same install

On Linux x86_64 and aarch64, macOS arm64 and Windows x86_64, `pip install starfold` gets a
wheel with the starfold server binary in it. On other platforms it installs the client alone,
which works against a server running elsewhere.

```python
import starfold

with starfold.start_server() as server:  # loopback, a free port, a generated password
    sf = server.client()  # signed in already
    sf.screenshot().save("desktop.png")
```

`start_server()` listens on 127.0.0.1 unless you pass `addr=`; `port=`, `password=` (an
empty one counts as none), `args=` (more server flags, `starfold --help`), `env=` (merged onto
this process's environment), `cwd=`, `binary=` (default `binary_path()`) and `timeout=`
(seconds until it answers, default 30) are optional. If the server exits, doesn't answer in
time or can't have its port, it raises `ServerStartError` with the server's last output in
`output`. It returns a `LocalServer` with `url`, `password`, `process`, `stderr_tail` (the
server's last lines of output), `client()`, `async_client()` and `close()`; the server stops on
`close()`, at the end of the `with` block, at exit, and when your process ends, however it
ends. On Linux and macOS `process` is a small `sh` guard whose child is the server. On Linux it
needs a display (`DISPLAY`, e.g. from Xvfb); it doesn't start one.

`starfold.binary_path()` is the binary: `$STARFOLD_BIN` if set, else the wheel's. The
`starfold` command runs it (`starfold --help`).

On Linux the server uses the system's libyuv, Opus and PulseAudio libraries and needs glibc
2.39 or newer (Ubuntu 24.04 or newer):

```sh
sudo apt install libyuv0 libopus0 libpulse0
```

Without them, `start_server()` and `starfold` say which libraries are missing.

## Tests

```sh
uv run pytest                                      # unit tests, no server
STARFOLD_BIN=../../target/release/starfold uv run pytest -m integration   # Linux, Xvfb + xterm
```
