Skip to main content

An asynchronous Python client library for the CDEK API

Project description

aiocdek - comprehensive asynchronous library for interaction with CDEK API

Python License

An asynchronous Python client library for the CDEK API. This SDK provides easy integration with CDEK delivery services, supporting all major API endpoints with type-safe models and comprehensive error handling.

Features

  • Fully Asynchronous: Built with aiohttp for non-blocking operations
  • Type Safety: Complete Pydantic models for all API requests and responses
  • Auto Authentication: Automatic OAuth token management with caching
  • Comprehensive Coverage: Support for all major CDEK API endpoints:
    • Order management (create, track, update)
    • Tariff calculation and comparison
    • Location and delivery point lookup
    • Courier services
    • Label and document printing
    • Webhook management
  • Error Handling: Robust error handling with detailed logging
  • Easy Integration: Simple, intuitive API design

Requirements

  • Python 3.9+
  • aiohttp
  • pydantic
  • loguru

Installation

pip install aiocdek

Or install from source:

git clone https://github.com/avoidedabsence/aiocdek.git
cd aiocdek
pip install -e .

Quick Start

import asyncio
from aiocdek import CDEKAPIClient
from aiocdek.models import OrderRequest, OrderPackage, OrderSender, OrderRecipient, Location, Money
from aiocdek.enums import TariffCode

async def main():
    # Initialize the client with your credentials
    client = CDEKAPIClient(
        client_id="your_client_id",
        client_secret="your_client_secret",
        test_environment=False, # If True, API URI = https://api.edu.cdek.ru/
        debug=False # If True, will log success/fail for each API request
    )
    
    # Calculate delivery cost
    from aiocdek.models import TariffRequest
    tariff_request = TariffRequest(
        type=1,  # Online store
        from_location=Location(code=270),  # Moscow
        to_location=Location(code=44),     # Ekaterinburg
        packages=[{
            "weight": 1000,  # 1kg
            "length": 30,
            "width": 20,
            "height": 10
        }]
    )
    
    tariff = await client.calculate_tariff(tariff_request)
    print(f"Delivery cost: {tariff.delivery_sum} RUB")
    
    # Create an order
    order = OrderRequest(
        type=1,  # Online store
        number="ORDER-001",
        tariff_code=TariffCode.EXPRESS_DOOR_TO_DOOR,
        sender=OrderSender(
            name="John Doe",
            phones=["+7123456789"]
        ),
        recipient=OrderRecipient(
            name="Jane Smith",
            phones=["+7987654321"]
        ),
        from_location=Location(code=270),
        to_location=Location(code=44),
        packages=[OrderPackage(
            number="PKG-001",
            weight=1000
        )]
    )
    
    result = await client.create_order(order)
    print(f"Order created: {result.entity.uuid}")

if __name__ == "__main__":
    asyncio.run(main())

License

This project is licensed under the GNU v3.0 License - see the LICENSE file for details.

Links

Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed description
  3. Include code examples and error messages

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

aiocdek-0.1.7.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiocdek-0.1.7-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file aiocdek-0.1.7.tar.gz.

File metadata

  • Download URL: aiocdek-0.1.7.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for aiocdek-0.1.7.tar.gz
Algorithm Hash digest
SHA256 5e0e29a4d2d71d80d0c693fd069b95355ad8d7273eabc08a44c2674016bf464e
MD5 82ec36f43dba38a6e291afdac15d6fbd
BLAKE2b-256 aee165bd1e7d1893cb6a8bca50ec5dc5f0a78002007b50939c2712ab581f1116

See more details on using hashes here.

File details

Details for the file aiocdek-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: aiocdek-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for aiocdek-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6a28146ff637122d06f9092a1d1003fd6e1fc2b245a4f820ed50292cd8e97ae6
MD5 d5c821a2b7315f6745bbf26bcc6af6b4
BLAKE2b-256 6c111e3b09282b5c7b220cfe3427a4fda6d236b31283fc6df7a04750e270457f

See more details on using hashes here.

Supported by

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