Metadata-Version: 2.4
Name: pereval-dating
Version: 1.0.0
Summary: Python SDK for the Pereval dating network partner API
License-Expression: MIT
Project-URL: Repository, https://github.com/pereval-dating/pereval-python
Project-URL: Documentation, https://pereval.dating/en/docs/
Project-URL: Issues, https://github.com/pereval-dating/pereval-python/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-extensions>=4.4
Provides-Extra: httpx
Requires-Dist: httpx<1,>=0.27; extra == "httpx"
Provides-Extra: requests
Requires-Dist: requests<3,>=2.31; extra == "requests"
Provides-Extra: aiohttp
Requires-Dist: aiohttp<4,>=3.10; extra == "aiohttp"
Provides-Extra: structlog
Requires-Dist: structlog>=24; extra == "structlog"
Provides-Extra: loguru
Requires-Dist: loguru>=0.7; extra == "loguru"
Provides-Extra: test
Requires-Dist: httpx<1,>=0.27; extra == "test"
Requires-Dist: requests<3,>=2.31; extra == "test"
Requires-Dist: aiohttp<4,>=3.10; extra == "test"
Requires-Dist: structlog>=24; extra == "test"
Requires-Dist: loguru>=0.7; extra == "test"
Dynamic: license-file

# Pereval SDK for Python

Server-side client for the Pereval partner API, protocol 1.0.1. Keep partner keys on your server. Use separate credentials, event cursors and storage for sandbox and live.

## Installation

Run `python -m pip install pereval-dating` on Python 3.10+. Import the package as `pereval`.

Run `python -m pip install .` from this checkout with Python 3.10 or newer.

Set `PEREVAL_API_KEY` to your sandbox key. The [quickstart](examples/quickstart.py) checks the mode without writing data.

```python
import os
from pereval import AsyncClient

async def feed(member_id: str):
    async with AsyncClient(
        os.environ["PEREVAL_API_KEY"],
        webhook_secret=os.environ["PEREVAL_WEBHOOK_SECRET"],
    ) as client:
        caps = await client.capabilities.get()
        if caps["mode"] != "sandbox":
            raise RuntimeError("Expected sandbox mode")
        return await client.feed.list(member_id, {"limit": 10})
```

## API

See [service methods](src/pereval/py_client.py) for arguments and defaults. Groups cover health, capabilities, languages, members, feed, likes, matches, messages, events, moderation, photos, commerce and MCP. JSON fields keep their wire names. Photo downloads return bytes and a content type. Only orders require the additional `commerce_key` option.

## Integrating with an existing application

Use `Client` with `with` and `AsyncClient` with `async with`. By default the SDK uses HTTPX when installed. Otherwise it uses the standard library with one HTTPS connection per request and a worker thread for async calls. For pooled connections install `pereval-dating[httpx]`. The timeout defaults to 20 seconds.

| Optional extra | Adapter for an existing instance |
| --- | --- |
| httpx | `httpx_transport(client)` or `async_httpx_transport(client)` |
| requests | `requests_transport(session)` |
| aiohttp | `aiohttp_transport(session)` |
| structlog | `structlog_logger(logger)` |
| loguru | `loguru_logger(logger)` |

```python
import logging
import os
import requests
from pereval import Client, requests_transport, logging_logger

with requests.Session() as session:
    with Client(os.environ["PEREVAL_API_KEY"],
                transport=requests_transport(session),
                logger=logging_logger(logging.getLogger("pereval"))) as client:
        print(client.capabilities.get()["mode"])
```

Implement `Sender` or `AsyncSender` with the SDK's Request and Response types. Honor request.timeout, never follow redirects and bound response reads to 15 MiB. AsyncClient accepts both sync and awaitable loggers. See [custom extensions](examples/extensions.py). Typed responses are described in `pereval.models`.

Applications own sessions and agents passed through adapters. Middleware receives the next sender and returns a sender. The first layer runs first. Log entries contain method, status, duration and level (info, warning or error). Avoid logging URLs, headers and payloads in custom code.

HTTP failures raise `ApiError` with status, code and detail. MCP errors raise `RpcError`. Transport exceptions propagate. There are no automatic retries. Use stable operation references when retrying supported writes. Redirects are disabled and responses are limited to 15 MiB.

## Event delivery

See [polling and webhook handlers](examples/events.py). Pass the original request bytes and the `X-Network-Signature` header to `client.webhooks.parse`. Persist each event once by ID across both delivery channels. Start polling at cursor 0 and save the next cursor only after the whole page succeeds.

## Tests

Install `build`, `ruff`, `mypy` and `.[test]` from the checkout. Run `python -m unittest discover -s tests`, `mypy src`, `ruff check src tests examples` and `python -m build`. Tests use local transports and require no partner credentials.

## Sandbox integration test

Use two dedicated test partners with a small feed. Set `PARTNER_A` and `PARTNER_B` through your environment. Optionally set `PEREVAL_ORIGIN` to a trusted HTTPS API origin. Run `python tests/sandbox.py` after installing dependencies. The test checks both partners for sandbox mode before writing. It creates two synthetic members, verifies batch updates, discovery, mutual likes, message deduplication, read receipts, event pagination and validation errors, then requests removal of its test members. Test events can still reach configured webhooks. Run this separately from the offline suite.

MIT license.
