Metadata-Version: 2.5
Name: getplantain
Version: 0.1.0
Summary: Python SDK for Plantain — generate Nano Banana 2.1 images and 4–8s video clips with sound.
Project-URL: Homepage, https://getplantain.com
Project-URL: Documentation, https://getplantain.com/docs
Project-URL: Repository, https://github.com/getplantain/plantain-python
Project-URL: Issues, https://github.com/getplantain/plantain-python/issues
Author-email: Plantain <hello@getplantain.com>
License: MIT License
        
        Copyright (c) 2026 Plantain
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-images,ai-video,getplantain,image-generation,nano-banana,plantain,sdk,video-generation
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.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.25
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# getplantain

Official Python SDK for **[Plantain](https://getplantain.com)** — generate **Nano Banana 2.1** 1K PNG images (€0.02 each, less in bulk) and **4–8 second MP4 video clips with sound** (€0.16 each, 720p or 1080p) in a few lines of Python.

- Handles submit, polling, and download automatically (sync and async)
- No Google Cloud account or billing setup required
- Pay-as-you-go in euros, no monthly subscription
- New accounts get **5 free credits** at [getplantain.com/signin](https://getplantain.com/signin)
- Failed or refused generations are automatically refunded

*Plantain is an independent service and is not affiliated with or endorsed by Google.*

## Installation

```bash
pip install getplantain
```

Requires Python 3.10+.

## Quick start

1. Sign in with Google at [getplantain.com/signin](https://getplantain.com/signin) to get an API key (includes 5 free credits).
2. Set `PLANTAIN_API_KEY` in your environment (or pass `api_key=...` directly).

```python
from plantain import Plantain

with Plantain() as client:
    # Generate a 1K PNG image (1 credit)
    image = client.generate_image(
        "A ceramic teapot and two cups on a linen tablecloth, soft morning light",
        aspect_ratio="16:9",
    )
    image.save("teapot.png")
    print(f"Job {image.job.id}, credits left: {image.job.credits_left}")

    # Generate a video clip with sound (8 credits)
    video = client.generate_video(
        "Waves rolling onto a rocky shore at golden hour, seagulls calling",
        duration_s=8,
        aspect_ratio="16:9",
        resolution="1080p",
    )
    video.save("waves.mp4")

    # Check account balance
    account = client.get_account()
    print(f"{account.name}: {account.credits} credits remaining")
```

### Async usage

```python
import asyncio
from plantain import AsyncPlantain

async def main() -> None:
    async with AsyncPlantain() as client:
        image = await client.generate_image("A sunlit ceramic bowl of ripe plantains")
        image.save("plantains.png")

asyncio.run(main())
```

### Step-by-step submit, poll, and download

If you want to store job IDs or poll separately:

```python
from plantain import Plantain

with Plantain() as client:
    job = client.submit_image("Minimalist lighthouse at dusk", aspect_ratio="3:4")
    print("Submitted:", job.id, "credits left:", job.credits_left)

    done = client.wait_for_image(job.id)
    png_bytes = client.download_image(done.id)
```

The same methods exist for video: `submit_video`, `get_video`, `wait_for_video`, and `download_video`.

## API reference

### `Plantain` / `AsyncPlantain`

Constructor options:

- `api_key`: Bearer API key (defaults to `PLANTAIN_API_KEY`)
- `base_url`: API base URL (defaults to `PLANTAIN_API_URL` or `https://getplantain.com`)
- `poll_interval`: Seconds between status checks while waiting (default `2.0`)
- `image_timeout`: Max wait in seconds for `generate_image` / `wait_for_image` (default `600.0`)
- `video_timeout`: Max wait in seconds for `generate_video` / `wait_for_video` (default `900.0`)
- `request_timeout`: HTTP timeout in seconds per request (default `60.0`)

Methods:

| Method | Endpoint | Cost | Returns |
|---|---|---:|---|
| `generate_image(prompt, *, aspect_ratio="1:1", tier="standard", ...)` | `POST` + poll + `GET /content` | 1 credit | `GeneratedImage` (`.job`, `.data`, `.content_type`, `.save(path)`) |
| `submit_image(prompt, *, aspect_ratio="1:1", tier="standard")` | `POST /v1/images` | 1 credit | `ImageJob` |
| `get_image(job_id)` | `GET /v1/images/{id}` | — | `ImageJob` |
| `wait_for_image(job_id, *, poll_interval=..., timeout=...)` | `GET /v1/images/{id}` | — | `ImageJob` |
| `download_image(job_id)` | `GET /v1/images/{id}/content` | — | `bytes` |
| `generate_video(prompt, *, duration_s=8, aspect_ratio="16:9", resolution="720p", ...)` | `POST` + poll + `GET /content` | 8 credits | `GeneratedVideo` (`.job`, `.data`, `.content_type`, `.save(path)`) |
| `submit_video(prompt, *, duration_s=8, aspect_ratio="16:9", resolution="720p")` | `POST /v1/videos` | 8 credits | `VideoJob` |
| `get_video(job_id)` | `GET /v1/videos/{id}` | — | `VideoJob` |
| `wait_for_video(job_id, *, poll_interval=..., timeout=...)` | `GET /v1/videos/{id}` | — | `VideoJob` |
| `download_video(job_id)` | `GET /v1/videos/{id}/content` | — | `bytes` |
| `get_account()` | `GET /v1/account` | — | `Account` |

Supported image aspect ratios: `"1:1"` (1024×1024, default), `"16:9"`, `"4:3"`, `"3:4"`, `"9:16"`.  
Supported video options: `duration_s` in `4`, `6`, `8` (default `8`); `aspect_ratio` in `"16:9"` (default), `"9:16"`; `resolution` in `"720p"` (default), `"1080p"`.

### Error handling

All SDK exceptions inherit from `PlantainError` (with `.status_code`, `.retry_after`, `.detail`, and `.job` where applicable):

- `AuthenticationError` (HTTP `401` or missing API key)
- `InsufficientCreditsError` (HTTP `402`)
- `NotFoundError` (HTTP `404`)
- `ConflictError` (HTTP `409`, content requested before job succeeded)
- `GoneError` (HTTP `410`, output no longer available)
- `ValidationError` (HTTP `422`)
- `RateLimitError` (HTTP `429`, sets `.retry_after` in seconds when provided)
- `JobFailedError` (job finished with status `"failed"`; credits are refunded automatically)
- `PlantainTimeoutError` (polling or HTTP request exceeded timeout)

```python
from plantain import InsufficientCreditsError, Plantain, PlantainError, RateLimitError

client = Plantain()
try:
    image = client.generate_image("A wooden sailboat on calm water")
except InsufficientCreditsError:
    print("Out of credits — top up at https://getplantain.com/account")
except RateLimitError as err:
    print(f"Queue busy — retry after {err.retry_after}s")
except PlantainError as err:
    print(f"API error: {err}")
```

## Pricing

- **1 credit** = one 1K image (Nano Banana 2.1, PNG)
- **8 credits** = one 4–8s video clip with sound (720p or 1080p, MP4)
- Credit packs: 1,000 credits for €20 (€0.02/image), 5,500 for €100 (€0.018), 31,000 for €500 (€0.016). Credits last 12 months from your last purchase.

## Development

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

## Support

Questions or feedback: [hello@getplantain.com](mailto:hello@getplantain.com) · [getplantain.com/docs](https://getplantain.com/docs)
