Skip to main content

pricezaim Python SDK

Python-клиент публичного API pricezaim. Синхронный, на httpx, с типами, DTO и проверкой подписи вебхуков.

Требуется Python 3.10+.

Установка

После публикации в PyPI:

pip install pricezaim-sdk

До публикации:

pip install "pricezaim-sdk @ git+https://github.com/horatiiwork-design/pricezaim-sdk-python.git"

Для приватного GitHub-репозитория нужен токен с доступом к нему.

Начало работы

import os

from pricezaim_sdk import Client

client = Client(os.environ["PRICEZAIM_API_KEY"])

page = client.auctions.list(status="active", per_page=20)

for auction in page:
    print(auction["id"], auction["title"])

print("Всего:", page.total)

Клиент можно закрывать явно или использовать как context manager:

with Client(os.environ["PRICEZAIM_API_KEY"]) as client:
    auctions = client.auctions.list()

Параметры клиента:

Client(
    api_key,
    base_url="https://api.pricezaim.ru",
    timeout=15.0,
    http_client=None,  # свой httpx.Client, если нужен прокси или тесты
)

Если API развёрнут под префиксом пути, укажите его в base_url: SDK добавляет только /v1/....

Ресурсы

Ресурс Что делает
client.auctions список, карточка, создание, изменение, запуск, архивация, победитель, отказ, фото и файлы
client.bids свои ставки, ставки аукциона, размещение ставки
client.deals список, карточка, документы, реквизиты, согласование, чат
client.webhooks создание, изменение, удаление, тестовая доставка, журнал и повтор доставки

Методы с суффиксом _dto возвращают dataclasses:

from pricezaim_sdk import Auction

auction = client.auctions.get_dto(991)

if isinstance(auction, Auction):
    print(auction.required_amount)
    print(auction.client_profile.inn if auction.client_profile else None)

DTO переживают неполный ответ: отсутствующие поля будут None или пустыми коллекциями. Исходный словарь доступен в to_dict().

Вебхуки

Подпись считается по сырому телу. Если пересобрать JSON, подпись не сойдётся.

import os

from pricezaim_sdk import WebhookEvent, WebhookEventType, verify_request

raw_body = request.body  # bytes, тело запроса из вашего фреймворка
headers = request.headers

if not verify_request(raw_body, os.environ["PRICEZAIM_WEBHOOK_SECRET"], headers):
    raise PermissionError("Invalid webhook signature")

event = WebhookEvent.from_json(raw_body)

if event.type is WebhookEventType.AUCTION_STARTED:
    auction_id = event.auction_id
    # ...

WebhookEvent отдаёт event_id, name, type, is_known, auction_id и payload. Неизвестное событие нужно залогировать и ответить 200, чтобы новые события на платформе не ломали приёмник.

Повторы запросов

По умолчанию выключены:

export PRICEZAIM_SDK_RETRIES_ENABLED=1
export PRICEZAIM_SDK_RETRY_ATTEMPTS=3
export PRICEZAIM_SDK_RETRY_BASE_DELAY_MS=200

Повторяются 429, 500, 502, 503, 504 и сетевые ошибки. GET, HEAD, PUT, DELETE, OPTIONS повторяются всегда; POST и PATCH — только с idempotency_key. Ответы 400, 401, 403, 404, 422 не повторяются. Retry-After учитывается.

Ошибки

from pricezaim_sdk import ApiError, ValidationError

try:
    client.auctions.get(999999)
except ValidationError as exc:
    print(exc.errors)
except ApiError as exc:
    print(exc.status, exc.error_code, exc.request_id, exc.retry_after)

TransportError выбрасывается при сетевой ошибке, таймауте или TLS.

Разработка

python -m pytest
ruff check src tests
mypy src
python -m build

Справочник по методам и типам — в docs/api.md.

Metadata

Release files for pricezaim-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pricezaim-sdk 0.1.0
File Size Uploaded Provenance Actions
pricezaim_sdk-0.1.0.tar.gz 26.6 kB Without provenance Details for pricezaim_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pricezaim-sdk 0.1.0
File Interpreter ABI Platform Actions
pricezaim_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for pricezaim_sdk-0.1.0-py3-none-any.whl

Total release size: 52.3 kB

Release files / pricezaim_sdk-0.1.0.tar.gz

Download URL pricezaim_sdk-0.1.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f482016d123d8df599b9e70bf51cc3577fbdcf6bf7eb65cec642e56e1f7d6918
BLAKE2b-256 checksum
How to use checksums
470b9b86cf655cd452d42faa42d531a72f8621654b26ed872b1aeb58329b2ed5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / pricezaim_sdk-0.1.0-py3-none-any.whl

Download URL pricezaim_sdk-0.1.0-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c7d979a12b297d0e20fd59c7bca77e1c9d31ff7e6923b94867576100e9c6643
BLAKE2b-256 checksum
How to use checksums
21b63c76933f105b931a59441755ce34e66e3261e789253b53dde3dffbefc733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for pricezaim-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page