Metadata-Version: 2.4
Name: byterover
Version: 0.3.0
Summary: The ByteRover Python SDK: search your team's drives and manage their documents through the ByteRover API.
Project-URL: Homepage, https://docs.byterover.ai
Project-URL: Documentation, https://docs.byterover.ai/api/python-sdk
Author: ByteRover, Inc.
License-Expression: MIT
License-File: LICENSE
Keywords: api,byterover,sdk,search
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx<1,>=0.27
Requires-Dist: pydantic<3,>=2.7
Description-Content-Type: text/markdown

# ByteRover Python SDK

The official Python SDK for the [ByteRover API](https://docs.byterover.ai/api/python-sdk): search your team's drives
and manage their documents.

```sh
pip install byterover
```

Python 3.11 or later; tested on 3.11, 3.12 and 3.13 · sync and thread-safe · typed

> **Upgrading from `byterover` 0.1.x?** Version 0.2 is a new SDK with a different API. To keep the old client, pin
> `byterover<0.2`.

## Quick start

Create an API key in ByteRover (**Team → API keys → Create key**) and set it as `BYTEROVER_API_KEY`.
See [Authentication](https://docs.byterover.ai/api/authentication).

```python
from byterover import ByteRover

client = ByteRover()  # reads BYTEROVER_API_KEY

found = client.search(
    query="How long do refunds take in the EU?",
    drive_ids=["drv_…"],
    effort="medium",
)

for result in found.results:
    print(result.text)
```

Use the client in a `with` block, or call `client.close()` when you're done.

## Configuration

```python
client = ByteRover(timeout=30.0, max_retries=2)  # api_key= overrides BYTEROVER_API_KEY
```

| Option | Default |
|---|---|
| `api_key` | `BYTEROVER_API_KEY` (required) |
| `base_url` | `BYTEROVER_BASE_URL`, then `https://byterover.ai/api` |
| `timeout` | 60 s per network step; 105 s for a `medium` search, 135 s for `high` |
| `max_retries` | 2 |
| `http_client` | a new `httpx.Client` |
| `logger` | none |

The SDK's error messages and logs never include the key, and the httpx errors it chains hold their request without
it. `repr(client)` shows only `brv_` and four characters.

## Usage

| Resource | Methods |
|---|---|
| `client.search` | search one or more drives |
| `client.key` | `retrieve` |
| `client.drives` | `list`, `retrieve` |
| `client.folders` | `list`, `create`, `move`, `delete` |
| `client.documents` | `list`, `retrieve`, `list_revisions`, `read`, `content`, `put_text`, `update`, `copy`, `delete`, `upload`, `upload_directory` |
| `client.uploads` | `create`, `list_parts`, `put_part`, `complete`, `resume` |
| `client.operations` | `retrieve`, `wait` |
| `client.request` | any other `/v1/` endpoint |

Field names match the API (`drive_ids`, `next_cursor`). Responses are pydantic models.

To rename a document or move it within its drive, use `documents.update(document_id, path=...)`;
`documents.copy(..., move=True)` moves it into another drive.

### Pagination

```python
for document in client.documents.list(drive_id, folder="/policies"):
    print(document.path)
```

### Raw responses

```python
answered = client.with_raw_response.documents.retrieve(document_id)
print(answered.status, answered.trace_id)
```

## Uploads

### Upload a file

```python
result = client.documents.upload(drive_id, "/reports/q3.pdf", "q3.pdf", wait="searchable")
print(result.document.id)
```

The SDK hashes the file, sends it in parts, retries failed parts and completes the upload. The source can be a file
path, bytes, a binary file opened with `open(path, "rb")`, or an object with `size` and `read(start, end)`.

### Resume after a crash

```python
from byterover import UploadIncompleteError

try:
    client.documents.upload(drive_id, path, file, on_upload_created=lambda saved: store.put(path, saved))
except UploadIncompleteError:
    client.uploads.resume(store.get(path), file)
```

If the upload already completed, `resume` answers `UPLOAD_CLOSED`: look for the path with `documents.list`.

### Upload a folder

```python
result = client.documents.upload_directory(drive_id, "handbook", prefix="/handbook")
print(len(result.succeeded), len(result.uploaded_not_ready), len(result.failed), len(result.skipped))
```

Hidden files, empty files and symbolic links are skipped. Links inside the folder are never followed, and a
subfolder or file swapped for a link while the folder is read is refused (in `failed`). The folder you pass is read
even when it is itself a link. The checks go by path, so a program that keeps swapping a folder for a link while the
upload runs could still, with exact timing, get a file from outside read: don't upload a folder that other programs
are changing. `uploaded_not_ready` files were uploaded but their wait failed: don't upload them again. Send the
`failed` ones again.

### Wait for processing

```python
result = client.documents.upload(drive_id, "/reports/q3.pdf", "q3.pdf")
client.operations.wait(result.operation.id)
```

More: [Uploads guide](https://docs.byterover.ai/api/python-sdk/uploads).

## Errors

Every error extends `ByteRoverError`. API errors extend `APIStatusError` and carry `status`, `code`, `message` and
`trace_id`.

```python
from byterover import NotFoundError, RateLimitError

try:
    client.documents.retrieve(document_id)
except NotFoundError:
    print("not found")
except RateLimitError:
    print("slow down")
```

| Status | Error |
|---|---|
| 400 | `BadRequestError` |
| 401 | `AuthenticationError` |
| 402 | `InsufficientBalanceError` |
| 403 | `PermissionDeniedError` |
| 404 | `NotFoundError` |
| 409 | `ConflictError` |
| 429 | `RateLimitError` |
| 500 and any other 5xx | `InternalServerError` |
| 503, 504 | `ServiceUnavailableError` |
| no response | `APIConnectionError`, `APITimeoutError` |

Quote the `trace_id` when you contact support.

## Retries

Reads are retried on connection errors, timeouts, 429 and 5xx. Writes and searches are retried only when they are known
not to have run (the connection failed before sending, or the API's own 429), so nothing runs twice.

After a write's outcome is unknown, check the state first, then send it again with the same `idempotency_key`. The API
answers a repeated key with the first result for 24 hours:

```python
client.documents.put_text(drive_id, path="/notes/today.txt", text=text, idempotency_key="notes-2026-11-15")
```

## Requirements

| | Supported |
|---|---|
| Python | 3.11 or later; tested on 3.11, 3.12 and 3.13 |
| Dependencies | `httpx` (BSD-3-Clause), `pydantic` (MIT) |

## Versioning

This SDK is at 0.x: a minor version (0.2 → 0.3) may include breaking changes; a patch version doesn't. Pin a minor
version, such as `byterover>=0.2,<0.3`. See [Versioning and support](https://docs.byterover.ai/api/sdk-versioning) and
the [changelog](https://docs.byterover.ai/changelog).

## Links

- [Python SDK docs](https://docs.byterover.ai/api/python-sdk)
- [API reference](https://docs.byterover.ai/api-reference/introduction)
- [Errors and retries](https://docs.byterover.ai/api/python-sdk/errors-and-retries)
- [Support](https://docs.byterover.ai/api/errors#get-help)

## License

MIT
