Metadata-Version: 2.4
Name: quantycat
Version: 0.2.0
Summary: Lightweight Python client for the private Iron Fleet robot service
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: cryptography>=44
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"

# QuantyCat Python SDK

## Core startup command (development)

The SDK provides `quantycat setup` and `python -m quantycat setup`. They reuse a
healthy QuantyCat Core or start an installed local Core in the background.
`quantycat serve` runs Core in the foreground. These commands never move a robot,
upgrade software, or change calibration automatically. Runtime logs are stored
under `$XDG_STATE_HOME/quantycat/core` (default `~/.local/state/quantycat/core`).

Setup can provision a signed compiled runtime when a release catalog and trusted
public key are pinned in the SDK. That installer is implemented and tested, but
no production release is configured in this checkout yet. Until then, install
Core from its local checkout or supply `QUANTYCAT_CORE_EXECUTABLE`. Missing or
unverified releases fail explicitly. Repeated/concurrent setup uses a startup lock.
Use `QUANTYCAT_CORE_ENDPOINT` or `--endpoint` to check another Core; a stopped
remote service is never started on the client computer.

Setup prompts for a robot name/model if needed, verifies existing connection and
calibration, and reuses the existing guided port/calibration workflow when work
is needed. SO-101 is the initial terminal-setup model. Active robot sessions are
preserved. Incomplete/noninteractive setup exits with code 2. `--runtime-only`
checks/starts the service without opening hardware or inspecting calibration.

Core serves the SDK's `/v1/rpc` API using the same worker as the UI. It tracks
command acknowledgements/completion, rejects competing writers, permits read-only
observers, and supports `client.stop()` without acquiring control. Ordinary SDK
calls never auto-start a service or fall back to opening a device themselves.

A lightweight Python client for QuantyCat Core. Core manages robot sessions and
workflows; Iron Fleet supplies hardware adapters, calibration algorithms, and IK.
The SDK does not include Iron Fleet, LeRobot, Rio, or hardware algorithms.

```python
import quantycat

quantycat.define("qubit", model="so101")
setup = quantycat.setup("qubit")

if setup.ready:
    with quantycat.connect("qubit") as robot:
        robot.help()
        print(robot.state().to_dict())
        robot.move(joint=4, by=5, unit="deg").wait(timeout=10)
        robot.go_home().wait(timeout=10)
```

The example commands physical movement when run against a physical robot. The SDK
and service are not published/deployed publicly yet.

## Installation and connection

Install this checkout with `pip install .` (or `pip install -e .` for development).
The client uses `cryptography` to verify runtime releases. Core must be running;
`quantycat setup` starts it when needed. Default endpoint: `http://127.0.0.1:8765`.

```python
client = quantycat.Client(endpoint="http://127.0.0.1:8765")
print(client.list_models())
```

Module-level calls use `QUANTYCAT_CORE_ENDPOINT` (or legacy `QUANTYCAT_ENDPOINT`)
and optional `QUANTYCAT_API_TOKEN`.
Sending a token to a non-loopback `http://` endpoint emits a warning; use HTTPS.
A `Client(endpoint=..., api_key=..., timeout=...)` can override these explicitly.
There is no automatic local-driver fallback or silent installation of software.

See [local development](docs/local-development.md) to start Core on this
workstation. Changing the endpoint connects the same client to another service;
remote operation still requires that service to reach the robot or a local agent.

## Available calls

- `define`, `load_definition`, `list_robots`, `list_models`, `get_model`.
- `setup`, `begin_setup`, `calibrate`, `discover_devices`, `check`.
- `connect`, `robot.state`, `robot.help`, `robot.joints`, `robot.joint_map`.
- `robot.move(joint=..., by=... or to=..., unit=...)`, `robot.move_joints`.
- `motion.refresh`, `motion.wait`, `motion.cancel`, `robot.stop`, `robot.close`.
- `set_home`, `go_home`, and their robot-session equivalents.
- `robot.start_teaching()`, `teaching.status()`, `teaching.finish(name)`,
  `teaching.abort()`, `robot.list_tasks()`, `robot.play_task(name).wait()`.
  These use Core's leader teaching, recording, storage, and timed playback.
  New recordings include calibration identity; incompatible/legacy unverified
  tasks are rejected by SDK playback. Visual tasks use the existing visual UI
  workflow rather than silently playing without corrections.
- Legacy Iron Fleet teaching prototype: `robot.set_hand_guiding(enabled)`,
  `robot.teaching_snapshot()`, `robot.plan_teaching(demonstration, targets=...)`.
  Hand guiding releases all motors; support the arm first. Ending it leaves
  motors released until an explicit move. Planning is read-only and runs in Iron
  Fleet. The old client-side example was removed from `test-qc-library`; its
  regression coverage remains in the backend projects. The migrated
  Core worker does not yet expose hand guiding and returns an explicit
  unsupported-operation error; leader teaching is available instead.

`go_home()` moves to the saved home pose. If none is saved it uses the model's
default pose, which can be far from the current pose and moves every joint in one
command. Save a home with `set_home()` first if that is not what you want.

Joint names, order, supported units, limits, and home defaults come from Iron
Fleet's selected model adapter. Other hardware requires a server-side adapter;
publishing this SDK does not imply support for every robot vendor.

`wait()` waits for Core's worker to report motion completion. It does not enforce a
position-accuracy threshold. A timeout does not automatically cancel movement.
Robot contexts close their remote sessions; stop results distinguish requested
from confirmed stopping. If the service refuses to close (for example a stop could
not be confirmed) the session stays held so you can `stop()` and `close()` again; a
close failure inside a `with` block is attached as a note and does not hide the
original exception. Read-only connections reject writes on the server.
Targets are not silently clipped by the client.

## Calibration files

When setup asks for a calibration file, enter a path on the computer running the
SDK. Its bytes are uploaded to Core for the selected Iron Fleet adapter to validate
and apply. The server never interprets that path as a path on its own machine.
The source file is not overwritten.

Robot definitions, calibration, saved home poses, and hardware ownership are
managed by Core using the existing deployment/calibration files. `Client(config_dir=...)` and local driver/adapter injection
are no longer SDK APIs; configure storage and adapters on the service instead.

## Service sessions

The SDK keeps active setup/robot sessions alive with heartbeats while scripts or
interactive prompts own them. If Core reports that a session has expired,
the next call raises `SessionExpiredError`; reconnect explicitly. Core attempts cleanup when a lease expires;
it retains ownership if hardware cleanup fails. Movement requests are not
silently retried after network errors. An uncertain reply must not be treated as
permission to repeat a move.

The initial service is for local development. Remote hosting needs authenticated
HTTPS deployment and a hardware-access/agent arrangement; moving a USB-connected
robot's backend to a cloud machine does not make that USB device remotely visible.

## Development

```bash
pip install -e '.[dev]'
pytest
ruff check .
python -m build
```

SDK protocol tests run against an in-process stub of the version-1 service
(`tests/conftest.py`). They cover the import boundary, protocol and HTTP error
handling, no-retry semantics, session close/expiry, motion waiting, and calibration
upload. Core owns end-to-end worker/setup/teaching/playback tests; hardware-adapter
contract tests remain in Iron Fleet. Removed client-side prototypes in
`test-qc-library` are historical; the root example now uses only the public SDK.
