Skip to main content

CDEK API wrapper

Project description

CDEK-API

Build Status Coverage Status PyPI Version

Описание

Библиотека упрощающая работу с API службы доставки СДЭК.

Установка

Для работы требуется Python 3.6+ Для установки используйте pipenv (или pip):

$ pipenv install fs-cdek-api
$ pip install fs-cdek-api

Примеры

Запрос доставки

delivery_request = DeliveryRequest(number='12345678')
order = delivery_request.add_order(
    number=randint(100000, 1000000),
    recipient_name='Иванов Иван Иванович',
    phone='+79999999999',
    send_city_post_code='680000',
    rec_city_post_code='680000',
    seller_name='Магазин',
    comment='Товар',
    tariff_type_code=138,
    shipping_price=300.0,
)
delivery_request.add_address(order, pvz_code='XAB1')
package = delivery_request.add_package(
    order_element=order,
    size_a=10,
    size_b=10,
    size_c=10,
    number=randint(100000, 1000000),
    barcode=randint(100000, 1000000),
    weight=600,
)
delivery_request.add_item(
    package_element=package,
    weight=500,
    cost=1000,
    ware_key='12345678',
    comment='Товар',
)

cdek_client = CDEKClient('login', 'pass')
delivery_orders = cdek_client.create_orders(delivery_request)

Удаление заказа

Условием возможности удаления заказа является отсутствие движения груза на складе СДЭК (статус заказа «Создан»).

delete_requests = cdek_client.delete_orders(
    act_number=act_number,
    dispatch_numbers=[dispatch_number],
)

Вызов курьера для забора груза ИМ

dispatch_number = order['DispatchNumber']

next_day = datetime.date.today() + datetime.timedelta(days=1)

call_courier = CallCourier()
call_request = call_courier.add_call(
    date=next_day,
    dispatch_number=dispatch_number,
    sender_phone='+79999999999',
    time_begin=datetime.time(hour=10),
    time_end=datetime.time(hour=17),
    lunch_begin=datetime.time(hour=13),
    lunch_end=datetime.time(hour=14),
)
call_courier.add_address(
    call_element=call_request,
    address_street='Пушкина',
    address_house='50',
    address_flat='1',
)

call = cdek_client.call_courier(call_courier)

Информация о заказах

dispatch_number = order['DispatchNumber']
info = cdek_client.get_orders_info([dispatch_number])

Статусы заказов

dispatch_number = order['DispatchNumber']
info = cdek_client.get_orders_statuses([dispatch_number])

Печать накладной

Возврщает pdf документ в случае успеха.

order_print = cdek_client.get_orders_print([dispatch_number])

Печать ШК-мест

Возврщает pdf документ в случае успеха.

barcode_print = cdek_client.get_barcode_print([dispatch_number])

Список регионов

regions = cdek_client.get_regions(region_code_ext=27)

Список городов

cities = cdek_client.get_cities(region_code_ext=27)

Список ПВЗ

pvz_list = cdek_client.get_delivery_points(city_post_code=680000)['pvz']

Расчет стоимости доставки

shipping_costs = cdek_client.get_shipping_cost(
    sender_city_id=270,
    receiver_city_id=44,
    goods=[
        {'weight': 0.3, 'length': 10, 'width': 7, 'height': 5},
        {'weight': 0.1, 'volume': 0.1},
    ],
    tariff_id=3,
)

Создание преалерта

next_day = datetime.date.today() + datetime.timedelta(days=1)

pre_alert_element = PreAlert(planned_meeting_date=next_day, pvz_code='XAB1')
pre_alert_element.add_order(dispatch_number=dispatch_number)
pre_alerts = cdek_client.create_prealerts(pre_alert_element)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fs-cdek-api-1.4.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

fs_cdek_api-1.4.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file fs-cdek-api-1.4.1.tar.gz.

File metadata

  • Download URL: fs-cdek-api-1.4.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for fs-cdek-api-1.4.1.tar.gz
Algorithm Hash digest
SHA256 973b92d7376ba1ac6e7c4dbb559da511f80f3020710b62876d25b4cde93271b9
MD5 cda758586ba91a17bb57be7feae6ae81
BLAKE2b-256 6d595cfbcbe04c9c9f92f614ccb9c486757e7bbf90e3a9dc085ad4b2367e0b56

See more details on using hashes here.

File details

Details for the file fs_cdek_api-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: fs_cdek_api-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for fs_cdek_api-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6bf91d17182f31be233993c94db69297198437a07e7dcfcb41f4ffa4cca7a67
MD5 d79d453ce9a654e721ffef92fcbd5f21
BLAKE2b-256 29e05a48f0c973aefaa994749c9df36643811b2879828a4ac0f508d0d29c8c47

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page