> For the complete documentation index, see [llms.txt](https://docs.orchard.airoverflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.orchard.airoverflow.com/quickstart/python.md).

# Python

Install `orchard-sdk` and set `ORCHARD_API_URL` + `ORCHARD_API_KEY` (see [Authentication](/auth.md)).

## Connect and list

```python
from orchard_sdk import Orchard

orchard = Orchard.from_env()

me = orchard.me()
print("acting as", me["username"], "in", me["active"]["name"])

for s in orchard.sandboxes.list()["instances"]:
    print(f"{s['name']:<18} {s['state']:<9} {s.get('tag') or '-'}")
```

The client holds an HTTP connection pool, use it as a context manager (or call `orchard.close()`), especially in short-lived scripts:

```python
with Orchard.from_env() as orchard:
    ...
```

## Address one sandbox

`orchard.sandbox(selector)` resolves a **uuid**, a **uuid prefix**, an exact **name**, or a **tag** to a handle:

```python
sb = orchard.sandbox("my-pixel")
print(sb.uuid, sb.get()["state"])

sb.start()
sb.tag("payments", "#22c55e")
sb.edit(notes="under test")
```

Ambiguous or missing selectors raise `orchard_sdk.SelectorError`.

## Create a sandbox

```python
job = orchard.sandboxes.create(
    platform="android",
    name="ci-pixel",
    image="system-images;android-35;google_apis;x86_64",
    device="pixel_7",
    cpu=4, memory_mb=4096,
)
print("launching on", job["node"])
```

## Stream logs

Live channels are context-managed iterators; leaving the block (or `break`) closes the socket cleanly:

```python
with sb.logs() as stream:
    for line in stream:
        print(line)
```

## Files and apps

```python
sb.files.upload("./build/app.apk", "/data/local/tmp")
sb.apps.install("./build/app.apk")
sb.files.download("/sdcard/Download/report.pdf", "./report.pdf")
```

## Error handling

```python
from orchard_sdk import ApiError, SelectorError

try:
    sb = orchard.sandbox("nope")
except SelectorError as e:
    print("no match:", e)
try:
    orchard.sandboxes.get("00000000-0000-0000-0000-000000000000").start()
except ApiError as e:
    print(e.status, e.user_message)
```

Next: [Scoped API keys](/guides/scoped-api-keys.md) · [Live channels](/guides/live-channels.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.orchard.airoverflow.com/quickstart/python.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
