Skip to main content

GoCream Labs × CDEK

PyPI - Status PyPI - Version PyPI - Downloads PyPI - Python Version

Tests - Running Coverage

Hatch project Gitmoji Built with Material for MkDocs linting - Ruff License - Mozilla Public License Version 2.0

Документация: gocream-labs.github.io/pycdek

gocream-pycdek — Python-библиотека для работы с CDEK API v2.0.

Установка

pip install gocream-pycdek

Стабильной версии пока нет, поэтому команда выше поставит последний release candidate. После выхода 2.0.0 предварительные версии ставятся флагом --pre:

pip install --pre gocream-pycdek

Импорт в Python выполняется через пакет gocream_pycdek:

from gocream_pycdek import CdekClient

client = CdekClient("client-id", "client-secret")

Быстрый старт

from gocream_pycdek import CdekClient
from gocream_pycdek import ContractType


client = CdekClient("client-id", "client-secret")

regions = client.get_regions()

order = client.registrate_order(
    136,
    {"name": "Иван Иванов", "phones": [{"number": "+79000000000"}]},
    [{"number": "1", "weight": 1000}],
    contract_type=ContractType.ONLINE_STORE,
    to_location={"code": 270},
)

Тип заказа указывается в каждом заказе, а не в клиенте: ContractType.DELIVERY доступен любому договору, ContractType.ONLINE_STORE — только договору с интернет-магазином, поэтому одна учётная запись может отправлять оба типа.

Параметр base_url=TEST_API_URL переключает клиент на тестовый контур СДЭК.

Жизненный цикл клиента

Клиент держит открытую HTTP-сессию и переиспользует соединение между запросами. Поэтому один долгоживущий клиент на приложение выгоднее, чем новый клиент на каждый запрос, — и поэтому же его нужно закрывать.

Для короткоживущего клиента достаточно блока with:

with CdekClient("client-id", "client-secret") as client:
    regions = client.get_regions()

Клиент, живущий всё время работы приложения, закрывается явно при завершении:

client = CdekClient("client-id", "client-secret")
try:
    regions = client.get_regions()
finally:
    client.close()

Если не закрыть, сокеты остаются открытыми, пока на клиента есть хоть одна ссылка. Сборщик мусора их в итоге освободит, но предупреждения при этом не будет, так что накопление дескрипторов легко пропустить — особенно если клиенты создаются на каждый запрос и оседают в кэше или контейнере зависимостей. После close() клиент остаётся рабочим: следующий запрос откроет соединение заново.

Статус проекта

Библиотека находится в процессе актуализации. До выхода стабильной версии 2.0.0 публичный API бета-версий может изменяться.

Дополнительные материалы

Лицензия

Проект распространяется по лицензии MPL-2.0.

Metadata

Release files for gocream-pycdek 2.0.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 gocream-pycdek 2.0.0
File Size Uploaded Provenance Actions
gocream_pycdek-2.0.0.tar.gz 98.6 kB With provenance Details for gocream_pycdek-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gocream-pycdek 2.0.0
File Interpreter ABI Platform Actions
gocream_pycdek-2.0.0-py3-none-any.whl Python 3 none any Details for gocream_pycdek-2.0.0-py3-none-any.whl

Total release size: 139.8 kB

Release files / gocream_pycdek-2.0.0.tar.gz

Download URL gocream_pycdek-2.0.0.tar.gz
Size 98.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e66917c5427eba222b4d4e5f4d238533f323d423809c22252c35576d6ae50960
BLAKE2b-256 checksum
How to use checksums
fd59cc33bf33e0c7da8c88059d8e6049ec0dfd341869cfb280f4b39bf4e19410
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gocream_pycdek-2.0.0-py3-none-any.whl

Download URL gocream_pycdek-2.0.0-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b25668fa696c97894f749e9c064bf1a9ce3a9b37eeb118b20a9e9f25025679c0
BLAKE2b-256 checksum
How to use checksums
07fc92722eacf759281961dd21848f7786521eed3cd442b9cf7f038d5157891c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Security for gocream-pycdek 2.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gocream_pycdek-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

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.

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