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.6.tar.gz (35.5 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.6-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocdek-0.1.6.tar.gz
  • Upload date:
  • Size: 35.5 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.6.tar.gz
Algorithm Hash digest
SHA256 6c6f3dfd05c636645511d4bd8e665572b68376853cd820565b4ebc0f0f620ebb
MD5 e98dd46c5ab1449f31126c60dc6143db
BLAKE2b-256 62bf0f9f9d9802c875fd7a48dcc60410e9ec58b91df1db2a798b814d23724d2e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiocdek-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a046824c6a5fef2a7dd5309f196640d2728f113944001b963d47e61405cc81eb
MD5 a130e18bbb3a7a37ea84bedacca82def
BLAKE2b-256 c8b20f2bba38aa538264088c3d44a2a947635340640a2c36bd78b842cb5955b5

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