Metadata-Version: 2.4
Name: starfold
Version: 0.3.2
Summary: Python SDK for starfold
License-Expression: MIT AND BSD-2-Clause AND BSD-3-Clause AND ISC AND Apache-2.0 AND Unicode-3.0 AND Zlib AND OFL-1.1 AND CC0-1.0 AND LicenseRef-AOM-Patent-License-1.0 AND ZPL-2.1 AND GPL-3.0-or-later WITH GCC-exception-3.1
License-File: LICENSE
License-File: THIRD_PARTY.md
License-File: licenses/COPYING-dav1d
License-File: licenses/COPYING-wasi-libc
License-File: licenses/GCC-runtime-copyright.txt
License-File: licenses/GPL-3.0.txt
License-File: licenses/MinGW-w64-copyright.txt
License-File: licenses/Opus-COPYING.txt
License-File: licenses/inter-LICENSE.txt
License-File: licenses/libaom-LICENSE-fastfeat.txt
License-File: licenses/libaom-LICENSE-vector.txt
License-File: licenses/libaom-LICENSE-x86inc.txt
License-File: licenses/libaom-LICENSE.txt
License-File: licenses/libaom-PATENTS.txt
License-File: licenses/libvpl-LICENSE.txt
License-File: licenses/libyuv-LICENSE.txt
License-File: licenses/rust-crates.txt
License-File: licenses/rust-std/Apache-2.0.txt
License-File: licenses/rust-std/BSD-2-Clause.txt
License-File: licenses/rust-std/CC-BY-SA-4.0.txt
License-File: licenses/rust-std/COPYRIGHT-library.html
License-File: licenses/rust-std/GCC-exception-3.1.txt
License-File: licenses/rust-std/GPL-2.0-only.txt
License-File: licenses/rust-std/GPL-3.0-or-later.txt
License-File: licenses/rust-std/ISC.txt
License-File: licenses/rust-std/LLVM-exception.txt
License-File: licenses/rust-std/MIT.txt
License-File: licenses/rust-std/NCSA.txt
License-File: licenses/rust-std/OFL-1.1.txt
License-File: licenses/rust-std/Unicode-3.0.txt
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
```
