Skip to main content

Asynchronous Python SDK for Digikala API

Project description

Digikala SDK

Asynchronous Python SDK for Digikala API

Python AsyncIO License

Fast • Type-Safe • Production-Ready

DocumentationQuick StartExamplesAPI Reference


Features

  • 🚀 Fully Asynchronous - Built on httpx.AsyncClient with async/await support
  • Type-Safe - Complete Pydantic v2 models with validation
  • 🔄 Automatic Retries - Intelligent retry logic with exponential backoff
  • Rate Limiting - Client-side rate limiting (optional with aiolimiter)
  • 💾 Caching - Response caching support (optional with aiocache)
  • 🛡️ Comprehensive Error Handling - Full exception hierarchy
  • 📝 Well-Documented - Extensive documentation and examples
  • 🧪 Well-Tested - 95%+ test coverage

Installation

Basic Installation

pip install digikala-sdk

With Optional Features

# With rate limiting
pip install digikala-sdk[ratelimit]

# With caching
pip install digikala-sdk[cache]

# With all features
pip install digikala-sdk[full]

Quick Start

import asyncio
from digikala_sdk import DigikalaClient

async def main():
    # Using context manager (recommended)
    async with DigikalaClient(api_key="your-api-key") as client:
        # Get product details
        product = await client.products.get_product(id=12345)
        print(f"Product: {product.data.product.title_fa}")
        print(f"Price: {product.data.product.default_variant.price.selling_price:,} Rials")

        # Search products
        results = await client.products.search(q="laptop")
        print(f"\nFound {results.data.pager.total_items} products")

asyncio.run(main())

👉 See more examples →


API Modules

Module Description Documentation
Products Product details and search 📚 Docs
Sellers Seller information and listings 📚 Docs
Brands Brand information and listings 📚 Docs

Advanced Features

Rate Limiting

from digikala_sdk import DigikalaClient, DigikalaConfig

config = DigikalaConfig(
    api_key="your-api-key",
    rate_limit_requests=50  # 50 requests per minute
)

async with DigikalaClient(config=config) as client:
    # Requests automatically throttled
    for product_id in product_ids:
        product = await client.products.get_product(id=product_id)

Response Caching

config = DigikalaConfig(
    api_key="your-api-key",
    cache_config={
        "enabled": True,
        "backend": "memory",  # or "redis"
        "ttl": 300  # 5 minutes
    }
)

async with DigikalaClient(config=config) as client:
    # GET requests cached automatically
    product = await client.products.get_product(id=12345)

👉 Full configuration guide →


Error Handling

from digikala_sdk import DigikalaClient
from digikala_sdk.exceptions import (
    NotFoundError,
    RateLimitError,
    DigikalaAPIError
)

async with DigikalaClient(api_key="your-api-key") as client:
    try:
        product = await client.products.get_product(id=12345)
    except NotFoundError:
        print("Product not found")
    except RateLimitError as e:
        print(f"Rate limited. Retry after {e.retry_after}s")
    except DigikalaAPIError as e:
        print(f"API error: {e}")

👉 Complete error handling guide →


Documentation

📚 Complete Documentation

📖 API References

💡 Examples

See the examples/ directory for complete examples:

  • Basic usage patterns
  • FastAPI integration
  • Advanced configuration
  • Error handling strategies

Requirements

  • Python: 3.8+
  • Dependencies:
    • httpx >= 0.24.0
    • pydantic >= 2.0.0
  • Optional:
    • aiolimiter >= 1.1.0 (for rate limiting)
    • aiocache >= 0.12.0 (for caching)

Project Structure

digikala-sdk/
├── docs/                    # 📚 Documentation
│   ├── SDK_Documentation.md
│   ├── products.md
│   ├── sellers.md
│   └── brands.md
├── examples/                # 💡 Usage examples
├── src/                     # 📦 Source code
│   ├── client.py           # Main client
│   ├── config.py           # Configuration
│   ├── exceptions.py       # Exceptions
│   ├── models/             # Pydantic models
│   └── services/           # API services
└── tests/                   # 🧪 Test suite

Development

Setup

# Clone repository
git clone https://github.com/digikala/digikala-sdk.git
cd digikala-sdk

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src tests/

# Run specific test file
pytest tests/test_products.py

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.


Support


Made with ❤️ by the Digikala SDK Team

DocumentationAPI ReferenceExamples

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

digikala_sdk-1.0.0.tar.gz (77.3 kB view details)

Uploaded Source

Built Distribution

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

digikala_sdk-1.0.0-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file digikala_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: digikala_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 77.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for digikala_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e19c5c07680ddd5dd081ba7a947f468d95bf054894d9e371927ec9f80c52801f
MD5 82a8dba9d849b8a08f56a5bdce2c5fac
BLAKE2b-256 b495a996bfd38644c1e1a88d807adaa25bc3532692c52b42cd60a3ea840a17df

See more details on using hashes here.

File details

Details for the file digikala_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: digikala_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for digikala_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f6f336851bd7815d4ed761ab5be643944943b145bb60d9038228912322d0d72
MD5 4c1142e875109799884bfeddb3745c4a
BLAKE2b-256 9c277e9eb107f1ee1209710ae3616b078584431facd89d301e6c807491c2aceb

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