Metadata-Version: 2.4
Name: serwin_sdk
Version: 0.2.1
Summary: SDK for Serwin cloud platform worker scripts
Author-email: Martin <your-email@example.com>
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: uuid

# serwin_sdk

SDK for writing worker scripts on the Serwin cloud platform. It handles moving
data in and out of your job — pulling input from a bucket, publishing results,
and deploying trained models — so your script can focus on the actual logic.

## Install

```bash
pip install serwin_sdk
```

## Quick start

```python
import os
from serwin_sdk import WorkersContext

ctx = WorkersContext(api_key=os.environ.get("API_KEY"))

# pull everything from a bucket into a local folder
ctx.input(bucket="my-input-bucket", dest_folder="input")

# ... your script's own logic goes here ...

# push everything in a local folder back up to a bucket
ctx.publish(dest_folder="output", bucketname="my-output-bucket")
```

## Configuration

`WorkersContext` reads its settings from environment variables set on the
worker VM at provision time. You can also pass any of them explicitly to
override the environment:

| Env var             | Purpose                                      |
|----------------------|-----------------------------------------------|
| `API_KEY`            | Authenticates requests to the control plane   |
| `CONTROL_PLANE_URL`  | Base URL of the control plane API             |
| `JOB_ID`             | Identifies the current run                    |
| `WORK_DIR`           | Local scratch directory (default `/tmp/work`) |

```python
ctx = WorkersContext(
    control_plane_url=os.environ.get("CONTROL_PLANE_URL"),
    job_id=os.environ.get("JOB_ID"),
    work_dir=os.environ.get("WORK_DIR"),
    api_key=os.environ.get("API_KEY"),
)
```

## API

### `ctx.input(bucket, dest_folder, filenames=None)`

Pulls data from a bucket into `dest_folder`. Omit `filenames` to pull the
whole bucket; pass a list to pull only those specific files.

```python
ctx.input(bucket="checko19", dest_folder="input")
ctx.input(bucket="checko19", dest_folder="input", filenames=["cars.csv"])
```

### `ctx.output(local_path, url)`

Uploads a single local file to a presigned upload URL.

### `ctx.publish(dest_folder, bucketname)`

Uploads everything under `dest_folder` to `bucketname`, preserving folder
structure.

```python
ctx.publish(dest_folder="output", bucketname="checko20")
```

### `ctx.deploy(model_path, profile, name=None)`

Uploads a trained model artifact (file or folder) and registers it with the
control plane as a deployable endpoint.

```python
ctx.deploy(model_path="model", profile="linear-regression", name="cars-price-model")
```

`profile` must be one of the platform's known pipeline profiles (e.g.
`linear-regression`, `llm-train`, `llm-infer`).

### `ctx.run_requirements(filepath="requirements.txt")`

Installs a `requirements.txt` next to your script before it runs, if one
exists. No-ops if the file isn't found.

## License

MIT
