Metadata-Version: 2.5
Name: zuppy
Version: 0.1.0
Summary: Official Python SDK for zuppy: upload code snippets, images and files
Project-URL: Homepage, https://zuppy.naekiz.com/docs
Project-URL: Repository, https://github.com/naekiz/zuppy-py
Project-URL: Issues, https://github.com/naekiz/zuppy-py/issues
License-Expression: MIT
License-File: LICENSE
Keywords: file-hosting,image-hosting,pastebin,sdk,snippet,upload,zuppy
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1,>=0.25
Provides-Extra: dev
Requires-Dist: anyio>=4; extra == 'dev'
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# zuppy

Official Python SDK for [zuppy](https://zuppy.naekiz.com): upload code snippets, images and files.

- Sync `Zuppy` and async `AsyncZuppy` clients (great for aiogram and other async bots)
- Upload bytes, paths or file objects; large files go in parallel parts with retries
- Fully typed, built on [httpx](https://www.python-httpx.org/)

```bash
pip install zuppy
```

Requires Python 3.9+. Create an API key at [zuppy.naekiz.com/api](https://zuppy.naekiz.com/api).

## Quick start

```python
from zuppy import Zuppy

zuppy = Zuppy("zpy_...")  # or set ZUPPY_KEY

snippet = zuppy.snippets.create('print("hi")', language="python")
print(snippet.url)  # https://zuppy.naekiz.com/aB3dE9xK

image = zuppy.files.upload("screenshot.png")
print(image.raw)  # https://zuppy.naekiz.com/raw/Xk29fLq1
```

Async:

```python
from zuppy import AsyncZuppy

async with AsyncZuppy() as zuppy:
    image = await zuppy.files.upload(photo_bytes, filename="photo.jpg")
```

## Client

```python
Zuppy(
    "zpy_...",                            # default: ZUPPY_KEY env variable
    base_url="https://zuppy.naekiz.com",  # default: ZUPPY_URL env variable or this
    timeout=60,                           # seconds or httpx.Timeout
    headers={},                           # extra headers for every request
    http_client=None,                     # your own httpx.Client / httpx.AsyncClient
)
```

Close it when done: `zuppy.close()` / `await zuppy.aclose()`, or use `with` / `async with`.

## Upload settings

Snippets and files take the same keyword arguments:

| Argument | Type | Default | |
|---|---|---|---|
| `title` | `str` | filename / `Untitled` | up to 100 characters |
| `description` | `str` | | up to 500 characters |
| `visibility` | `"public"` / `"private"` | `"public"` | `private`: only you |
| `expiration` | `"1d"` / `"1w"` / `"1m"` / `"never"` | `"1w"` | `1m` and `never` on paid plans |
| `password` | `str` | | 4–128 characters |
| `burn` | `bool` | `False` | deleted after the first guest opens it |
| `collection` | `str` | | collection id |

Every upload returns `UploadLinks` with `id`, `url`, `raw` (and `cdn` for accounts with CDN access).

## Snippets

```python
zuppy.snippets.create(
    open("script.py", "rb").read(),  # str or bytes, up to 512 KB
    language="python",               # default: "text"
    title="Scraper",
    expiration="1d",
)
```

All languages: `zuppy.SNIPPET_LANGUAGES`.

## Files and images

```python
zuppy.files.upload("video.mp4")                       # path: str or pathlib.Path
zuppy.files.upload(data, filename="cat.gif")          # bytes, bytearray or memoryview
zuppy.files.upload(open("cat.gif", "rb"))             # binary file object
zuppy.files.upload(io.BytesIO(data), filename="a.png")

zuppy.files.upload(
    "big.zip",
    content_type="application/zip",  # guessed from the filename by default
    convert=False,                   # keep GIF as is instead of converting to MP4
    visibility="private",
    on_progress=lambda loaded, total: print(f"{loaded * 100 // total}%"),
)
```

Files from 20 MB are uploaded in 10 MB parts, 3 at a time, each retried up to 5 times on network and server errors. Tune it with `multipart`, `concurrency` and `retries`. If the upload fails or is interrupted (Ctrl+C, task cancellation), the unfinished upload is removed from the server.

Size limits: 50 MB per file on the free plan, 1 GB on paid plans, plus your storage limit.

## Uploads

```python
page = zuppy.uploads.list(
    type="file",        # "file" or "snippet"
    q="screenshot",     # search by title and filename
    sort="size",        # "date", "name", "size", "views"
    order="desc",
    limit=20,           # 1–50
    offset=0,
    collection="none",  # collection id, or "none"
)
print(page.total, page.has_more, page.items)

for upload in zuppy.uploads.iterate(type="snippet"):  # async: async for
    print(upload.title)

upload = zuppy.uploads.get("aB3dE9xK")  # SnippetUpload or FileUpload
if upload.type == "snippet":
    print(upload.content)

zuppy.uploads.update("aB3dE9xK", title="New title", password=None, collection=None)  # None removes
zuppy.uploads.delete("aB3dE9xK")

data = zuppy.uploads.download("aB3dE9xK")                # bytes
thumb = zuppy.uploads.download("aB3dE9xK", thumb=True)   # 480px WebP
locked = zuppy.uploads.download("Xk29fLq1", password="hunter2")
```

## Collections

```python
collections = zuppy.collections.list()  # .items, .unsorted
shots = zuppy.collections.create("Screenshots")
zuppy.collections.rename(shots.id, "Shots")
zuppy.collections.delete(shots.id)  # uploads stay

zuppy.files.upload("a.png", collection=shots.id)
```

## Stats

```python
stats = zuppy.stats()  # .uploads, .files, .snippets, .views, .downloads
```

## Errors

Failed requests raise `ZuppyError` with the server message, the HTTP `status` (`0` for network errors) and optional `data`:

```python
from zuppy import ZuppyError

try:
    zuppy.uploads.get("Xk29fLq1")
except ZuppyError as error:
    if error.status == 401:
        print(error.message)  # "This upload is password protected"
```

## aiogram example

```python
from aiogram import Bot, F, Router
from aiogram.types import Message
from zuppy import AsyncZuppy

router = Router()
zuppy = AsyncZuppy()

@router.message(F.photo)
async def on_photo(message: Message, bot: Bot) -> None:
    file = await bot.download(message.photo[-1])
    link = await zuppy.files.upload(file, filename="photo.jpg")
    await message.answer(link.url)
```

## Development

```bash
python -m venv .venv
.venv/Scripts/pip install -e ".[dev]"   # Linux/macOS: .venv/bin/pip
pytest
mypy
```
