Metadata-Version: 2.4
Name: mezi
Version: 0.1.0
Summary: The mezi API client and webhook verifier. Standard library only.
Author: Pentarosa Co.
License: MIT
Project-URL: Homepage, https://developer.mezi.app
Project-URL: Documentation, https://developer.mezi.app/guides/client
Keywords: mezi,api,webhooks,payments
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# mezi

The mezi API client and webhook verifier for Python 3.9 or newer. Standard library only.

mezi holds a buyer's payment until they approve the work, then releases it. The API reads your account, deals and events. Nothing in it moves money.

```sh
pip install mezi
```

Keep the key in `MEZI_API_KEY`, on a server.

## Read your deals

```python
from mezi import MeziClient

mezi = MeziClient()  # reads MEZI_API_KEY
for deal in mezi.all_deals(role="owner"):
    print(deal["id"], deal["state"], deal["amountCents"])
```

## Follow events as they happen

```python
from mezi import MeziClient

mezi = MeziClient()
for event in mezi.stream_events(types=["deal.funded", "payout.released"]):
    print(event["id"], event["type"], event["data"]["id"])  # dedupe on event["id"]
```

Where a proxy cuts long connections, `mezi.watch_events()` does the same job by polling. Both take `cursor` and `on_cursor` so a restart resumes where it stopped.

## Check a webhook

```python
import os
from flask import Flask, request
from mezi import verify_webhook, WebhookVerificationError

app = Flask(__name__)

@app.post("/mezi/webhooks")
def mezi_webhook():
    try:
        event = verify_webhook(
            request.get_data(), request.headers.get("Mezi-Signature"), os.environ["MEZI_WEBHOOK_SECRET"]
        )
    except WebhookVerificationError:
        return "", 400
    print(event["type"], event["data"]["id"])
    return "", 204
```

Errors from the API raise `MeziApiError`; branch on `err.code` (for example `DEAL_NOT_FOUND`).

Full guide: https://developer.mezi.app/guides/client
