Metadata-Version: 2.4
Name: varya-avataar
Version: 0.2.1
Summary: Python client for the Varya video generation API
Project-URL: Homepage, https://varya.avataar.ai
Project-URL: Documentation, https://github.com/SoulVisionCreations/varya-python#readme
Project-URL: Source, https://github.com/SoulVisionCreations/varya-python
Author: Varya
License: MIT
License-File: LICENSE
Keywords: ai,api,generation,sdk,text-to-video,varya,video
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Requires-Dist: requests>=2.25
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == 'dev'
Description-Content-Type: text/markdown

# varya-avataar (Python)

Python client for the **Varya** video generation API. Submit a text (or image)
prompt, and the client handles the async job lifecycle — submit, poll, and
download — for you.

## Install

```bash
pip install varya-avataar
```

> Installs as `varya-avataar` on PyPI but **imports as `varya`**:
> `from varya import VaryaClient`.


Requires Python 3.8+ and `[requests](https://pypi.org/project/requests/)`.

## Authentication

Create a key in the Varya web app (**Account menu → API key**). It looks like
`sk_live_…`. Keep it secret; it draws down your account's credit balance.

```bash
export VARYA_API_KEY=sk_live_xxxxx
```

## Quick start

```python
from varya import VaryaClient, estimate_credits

client = VaryaClient(api_key="sk_live_xxxxx")

result = client.generate_video(
    "A snow leopard prowling the Himalayan slopes at dawn",
    resolution="480p",   # "480p" | "760p"
    duration=5,           # seconds, 1–15 (under 5 renders and bills as 5)
    aspect_ratio="16:9",  # 21:9 16:9 3:2 4:3 5:4 1:1 4:5 3:4 2:3 9:16 9:21
    on_status=print,
)

print(result["video_url"])
print(estimate_credits(5, "480p"))  # 1
client.download(result["video_url"], "out.mp4")
```

> For a full end-to-end walkthrough (text-to-video, image-to-video, first+last
> frame, and references), see **[USAGE.md](./USAGE.md)**.

`VaryaClient` is also a context manager (`with VaryaClient(...) as client:`)
which closes the underlying HTTP session on exit.

Image-to-video, first+last frame, and references:

```python
client.generate_video("make it move", image_path="ref.png")
client.generate_video("walk across", image_path="start.png", last_image_path="end.png")
client.generate_video("match these", refs=["look.png", "mood.png", "voice.mp3"])
```

Continue a video (prompt only; the result is the whole joined story):

```python
first = client.generate_video("a red kite flying over a green hill")
story = client.generate_video(
    "the kite string snaps and it drifts away",
    continue_from=first["generation_id"],
)
print(story["video_url"])  # first clip + new clip, joined
```

## CLI

Installing the package also installs a `varya` command:

```bash
# create a new video and download it
varya "a cat surfing a wave" --resolution 760p --output out.mp4

# resume / fetch an existing generation (no prompt, nothing re-charged)
varya --get gen_xxxxxxxx --output out.mp4
```

Run `varya --help` for all flags (`--duration`, `--resolution`, `--aspect-ratio`,
`--seed`, `--image`, `--last-image`, `--ref`, `--continue-from`, `--timeout`, …).

The key is read from `--key` or `$VARYA_API_KEY`; the base URL from
`--base-url` or `$VARYA_BASE_URL`.

## API

### `VaryaClient(api_key, base_url=..., auth_scheme="x-api-key", connect_timeout=15, read_timeout=60)`


| Method                                                              | Description                                                                                   |
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `generate_video(prompt, **opts)`                                    | Submit **and** wait. Returns the final result `dict`. The 90% path.                           |
| `submit(prompt, **opts)`                                            | `POST /api/generations`; returns `{ generation_id, status, product, task, credits_charged, … }`. |
| `status(generation_id)`                                             | `GET /generations/{id}`; current status/result.                                               |
| `wait(generation_id, poll_interval=2, timeout=900, on_status=None)` | Poll until `completed`/`failed`.                                                              |
| `download(url, dest)`                                               | Stream a finished video URL to a local file.                                                  |


**Generation options** (for `generate_video` / `submit`): `resolution`
(`"480p"` / `"760p"`), `duration` (1–15 s; under 5 renders as 5), `aspect_ratio`
(11 ratios, default `"16:9"`), `seed`, `image_path`, `last_image_path`, and
`refs` (list of paths; up to 5 images + 1 audio; not with image fields), and
`continue_from` (a completed `generation_id` to extend; not with image or ref
fields).

`style`, `enhance`, and `apply_watermark` are accepted but ignored and not sent.
Prompt enhancement is always on; output is always watermarked.

> Single-clip only: the client targets `POST /api/generations`. There is
> no compare / continuation mode and `fps` is fixed server-side. `duration`
> outside 1–15 raises `LONG_FORM_NOT_SUPPORTED` before any request is sent.

### Result shape

- **completed**: `{ "status": "completed", "video_url": "https://…", "product", "task", … }`
- **failed**: `{ "status": "failed", "error": "…", "error_code": "…" }` — branch
  on `error_code`, not the placeholder `error` text.

### Errors

Business/API failures raise `VaryaError` with a `.code`, `.status`, and optional
`.retry_after`:

```python
from varya import VaryaError

try:
    client.generate_video("…")
except VaryaError as e:
    if e.code == "INSUFFICIENT_CREDITS":
        ...  # top up
    elif e.code == "NSFW_CONTENT_BLOCKED":
        ...  # adjust the prompt/image
    else:
        raise
```

## Notes

- **Seed.** A `seed` is always sent. When you don't pass one it's randomized
client-side (in `[100, 1_000_000)`, matching the web app) and returned on the
result as `seed`, so you can reproduce a run by passing that same `seed` back.
- **Async by design.** Jobs are queued; the client polls every ~2s. Default
wait timeout is 15 minutes — typical times are 15–60s (480p 5s) to 2–3 min
(760p 15s) plus queue wait.
- **Resilient polling.** One keep-alive connection is reused, idempotent `GET`s
are retried with backoff, and `Retry-After` on 429/503 is honoured.
`POST /api/generations` is retried once on HTTP 500.
- **Auth header.** Defaults to `X-API-Key`. If your deployment expects
`Authorization: Bearer`, pass `auth_scheme="bearer"`.
- **Cost.** `ceil(max(duration, 5) / 5) × (480p=1, 760p=2)`. Use
`estimate_credits(duration, resolution)`. The exact charge is returned as
`credits_charged`. Failures after accept are refunded automatically.

## Development

```bash
pip install -e ".[dev]"
pytest
```

## License

MIT
