Metadata-Version: 2.5
Name: privconvert
Version: 0.2.0
Summary: Official Python client for the PrivConvert file conversion API. Files are processed in memory and never stored.
Project-URL: Homepage, https://privconvert.com/developers/
Project-URL: Documentation, https://privconvert.com/docs/
Project-URL: Source, https://github.com/toprivHQ/privconvert-python
Author-email: PrivConvert <contact@topriv.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api,converter,file conversion,pdf,privacy,privconvert
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: s3
Requires-Dist: boto3>=1.36; extra == 's3'
Description-Content-Type: text/markdown

# PrivConvert for Python

Official Python client for the [PrivConvert API](https://privconvert.com/developers/): file conversion for your app with zero data retention. Every file is processed in memory on our side and never written to disk.

- No dependencies, standard library only (S3 support is an optional extra)
- Python 3.10+
- Large files (above 90 MB) are uploaded in parts automatically
- Async jobs, webhook signature verification and typed errors included

## Install

```bash
pip install privconvert
```

## Quick start

Create a key on your [account page](https://privconvert.com/account/#apikeys) (new accounts can start a free trial of 25 conversions) and set it as an environment variable:

```bash
export PRIVCONVERT_API_KEY=pk_live_...
```

```python
from privconvert import PrivConvert

pc = PrivConvert()

result = pc.convert("word-to-pdf", "contract.docx")
result.save("contract.pdf")
print(result.credits_remaining)
```

`file` can be a path, `bytes`, or a binary file object. Extra keyword arguments are sent as form fields:

```python
pc.convert("compress-image", open("photo.png", "rb"), quality=70).save("photo-small.png")
pc.convert("resize-image", image_bytes, filename="in.jpg", width=800)
```

The tool id is the same slug as on the site. List them with `pc.tools()` or `pc.tools(category="document")`.

## Many files at once

Up to 20 files in one request, returned as a ZIP. A batch costs one slot of your per-minute rate limit.

```python
zip_result = pc.convert_batch("png-to-jpg", ["a.png", "b.png", "c.png"])
zip_result.save("converted.zip")
if zip_result.partial:
    print(zip_result.failed_count, "files were skipped, see PRIVCONVERT-ERRORS.txt in the ZIP")
```

## Files in Amazon S3

Convert a file that lives in S3 and write the result back to S3:

```bash
pip install "privconvert[s3]"
```

```python
pc.convert_storage(
    "word-to-pdf",
    source="s3://my-bucket/input.docx",
    destination="s3://my-bucket/output.pdf",
)
```

The file moves between your bucket and PrivConvert from wherever this code runs, using your own AWS credentials (the standard boto3 chain: environment, profile or IAM role). Your credentials are never sent to PrivConvert, and we never get access to your bucket. Run it in the same region as the bucket and the transfer is fast and cheap.

```python
import boto3

pc.convert_storage(
    "word-to-pdf",
    "s3://in-bucket/contract.docx",
    "s3://out-bucket/contract.pdf",
    s3_client=boto3.client("s3", region_name="eu-west-1"),
    upload_args={"ServerSideEncryption": "aws:kms"},  # passed to put_object
    overwrite=False,  # leave an existing file alone, before any credit is spent
)
```

Storage problems raise `StorageError`, with the provider's code in `code` (for example `NoSuchKey` or `AccessDenied`). Google Cloud Storage and Azure Blob Storage are planned.

## Async jobs

```python
job = pc.submit_job("pptx-to-pdf", "deck.pptx")
# job.key is returned once. Keep it if you need to download later or verify webhooks.
result = pc.wait(job)          # polls, downloads, then deletes the stored result
result.save("deck.pdf")
```

With a webhook instead of polling:

```python
job = pc.submit_job("pptx-to-pdf", "deck.pptx", webhook_url="https://example.com/hooks/privconvert")
save_somewhere(job.id, job.key)
# later, when the webhook arrives:
result = pc.download_job(job)
```

## Verifying webhooks

Pass the raw request bytes, not parsed JSON:

```python
from privconvert import verify_webhook

@app.post("/hooks/privconvert")
def hook():
    job_key = load_job_key(request.json["id"])
    if not verify_webhook(job_key, request.headers.get("X-PrivConvert-Signature"), request.get_data()):
        abort(400)
    ...
```

Deliveries older than 5 minutes are rejected as replays (`tolerance_s` to change it).

## Errors

Every error is a `PrivConvertError` with `status`, `code`, `message` and `retry_after`:

| Exception | When |
| --- | --- |
| `AuthenticationError` | Missing or invalid key (401) |
| `BadRequestError` | Bad request or unreadable input (400) |
| `FileTooLargeError` | Above your plan's size limit (413) |
| `UnsupportedTypeError` | Wrong input type for the tool (415) |
| `ConversionFailedError` | File read but could not be converted (422) |
| `RateLimitError` | Per-minute rate or monthly quota exceeded (429) |
| `ConcurrencyLimitError` | Too many conversions at once (429) |
| `ServerError` | Problem on our side (5xx) |
| `StorageError` | Reading from or writing to your S3 bucket failed |

Short 429, 502, 503 and 504 responses are retried automatically (`max_retries=2`), honouring `Retry-After`. A long `Retry-After`, which means the monthly quota is used up, raises at once instead of sleeping.

## Usage and limits

```python
pc.me()
# {'tier': 'growth', 'quota': 25000, 'used': 1234, 'remaining': 23766, 'rpm': 120, ...}
```

## Security notes

- The key is read from `PRIVCONVERT_API_KEY` or passed explicitly, and never appears in `repr()` or error messages.
- Requests go over HTTPS only. A plain `http://` base URL is refused.
- This package writes nothing to disk except where you call `Result.save()`.
- `convert_storage` keeps the file in memory between your bucket and the API. Your cloud credentials stay with you.

## Links

- [API documentation](https://privconvert.com/docs/)
- [Pricing and free trial](https://privconvert.com/developers/)
- Support: contact@topriv.com

MIT License
