Вебхуки¶
cdekx.webhooks.events.WebhookEvent
¶
cdekx.webhooks.events.parse_event(payload)
¶
Parse the body of an incoming webhook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Any
|
a dict or a JSON string from CDEK. |
required |
Returns:
| Type | Description |
|---|---|
WebhookEvent
|
class: |
Raises:
| Type | Description |
|---|---|
UnknownEventError
|
the payload has none of the required event fields. |
Example
event = parse_event({ # doctest: +SKIP ... "type": "ORDER_STATUS", ... "date_time": "2026-05-01T12:30:00+0300", ... "uuid": "8dea00e3-9aab-4d8e-887c-ef2aaa546456", ... "attributes": {"code": "DELIVERED", "cdek_number": "1234567890"}, ... })
cdekx.webhooks.events.PrintFormAttributes
¶
cdekx.webhooks.asgi.WebhookApp
¶
A small application for receiving webhooks (Starlette under the hood).
asgi
property
¶
The ASGI app (built lazily so Starlette is not required at import time).
handle_raw(body, *, path='', client_ip=None)
async
¶
Handle a raw request body.
Returns:
| Type | Description |
|---|---|
int
|
A |
dict[str, Any]
|
integrating with frameworks other than Starlette. |
cdekx.webhooks.security
¶
Hardening the webhook receiver endpoint.
The platform limitations matter here:
- CDEK does not sign the webhook body with an HMAC signature (unlike, say, Telegram or Stripe). The only built-in defences are checking the sender IP and your own "secret path" in the subscription URL.
- The recommended layout is therefore
https://example.com/webhooks/cdek/{secret}, wheresecretis a random string of 32+ characters known only to you. An HMAC helper is provided below for the case where you proxy events through your own service that signs them.
CDEK IP ranges change from time to time: check CDEK_IP_RANGES against the
documentation or support before enabling strict verification.
is_cdek_ip(ip, ranges=CDEK_IP_RANGES)
¶
Check whether an IP falls into the known CDEK ranges.
Returns False when the range list is empty (verification not configured)
so that traffic is not blocked by default.
verify_ip(ip, ranges=CDEK_IP_RANGES)
¶
Raise PermissionError if the IP is outside the CDEK ranges.
compare_signature(body, signature, secret)
¶
Verify an HMAC-SHA256 signature of the body (for your own proxy layer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
bytes
|
raw request body bytes. |
required |
signature
|
str | None
|
value of the signature header (hex or |
required |
secret
|
str
|
your shared secret. |
required |
allowed_types(event_types)
¶
Normalise the list of allowed event types (None means all).