Metadata-Version: 2.4
Name: spxrk-sdk
Version: 0.1.0
Summary: Server-side catalog, order and webhook client for the SPXRK API
Author: SPXRK
Project-URL: Homepage, https://spxrk.org
Project-URL: Documentation, https://spxrk.org/docs/guide
Keywords: spxrk,digital-goods,orders
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# SPXRK SDK for Python

A synchronous, server-side Python 3.10+ client for the SPXRK catalog and order API. The package uses the Python standard library. Package name for this release candidate is `spxrk-sdk`. Import name is `spxrk`. Install this checkout with `python -m pip install .` from this directory.

```python
import os
from spxrk import Client

client = Client(os.environ["SPXRK_API_KEY"])
page = client.products(group="telegram", limit=10)
for product in page["data"]:
    print(product["sku"], product["name"])
```

## Methods

| Method | Partner API |
| --- | --- |
| `categories()` | GET /v1/categories |
| `products(group=…, category=…, q=…, region=…, variant=…, limit=…, offset=…)` | GET /v1/products |
| `product(sku)` | GET /v1/products/{sku} |
| `validate(sku, delivery)` | POST /v1/products/{sku}/validate |
| `create_order(order, idempotency_key=…)` | POST /v1/orders |
| `order(order_id)` | GET /v1/orders/{order_id} |

Successful calls return decoded JSON objects. Pagination uses `next_offset` until it is null. Store one idempotency key and the exact body per checkout before sending an order. A replay after timeout must use both saved values. Calls have a configurable 15-second socket timeout and make a single attempt. `ApiError` exposes `status`, `code`, `request_id`, and `retry_after`. Network failures raise standard library transport exceptions. Malformed JSON in a successful response raises `ProtocolError`.

`verify_webhook(secret, raw_body, headers)` verifies HMAC, timestamp, event ID and event type and returns the signed JSON object. Persist each event once using its ID, then acknowledge delivery. The webhook secret is distinct from an API key. Keep secrets, authorization headers, recipient handles and delivered codes out of logs. [SPXRK integration guide](https://spxrk.org/docs/guide)

## Tests and local distributions

```sh
PYTHONPATH=src python -m unittest discover -s tests -v
python -m pip install build
python -m build
```

The generated files in `dist/` can be inspected and installed locally. Registry publication requires control of the project name and a release decision from the SPXRK maintainer.

## По-русски

Установите локальную копию командой `python -m pip install .`. Укажите тестовый ключ из кабинета в `SPXRK_API_KEY`. Метод `products()` возвращает страницу каталога. Для проверки следующих страниц передавайте `next_offset` в `offset`, пока значение не станет `None`. Для API-ключа нужны `orders:read` для чтения и `orders:write` для создания заказов.

Перед вызовом `create_order()` сохраните тело заказа и постоянный ключ своей покупки. После обрыва соединения используйте их повторно. Сохраните полученный `id` и запросите состояние через `order(id)`. Сумма каталога хранится в целых единицах по 1/100000 USD. Для обработки уведомления передайте `verify_webhook()` байты тела до разбора JSON. Разбор ошибок, тестовый заказ и обработчик дублей представлены в руководстве. [Документация SPXRK](https://spxrk.org/docs/guide)
