Asynchronous Python SDK for Digikala API
Project description
Digikala SDK
Asynchronous Python SDK for Digikala API
Fast • Type-Safe • Production-Ready
Features
- 🚀 Fully Asynchronous - Built on
httpx.AsyncClientwith 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())
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)
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
- SDK Documentation - Complete SDK manual
- Quick Start Guide - Get started quickly
- Error Handling - Exception handling guide
📖 API References
- Products API - Product operations
- Sellers API - Seller operations
- Brands API - Brand operations
💡 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.0pydantic >= 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📚 Documentation: docs/SDK_Documentation.md
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
Made with ❤️ by the Digikala SDK Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e19c5c07680ddd5dd081ba7a947f468d95bf054894d9e371927ec9f80c52801f
|
|
| MD5 |
82a8dba9d849b8a08f56a5bdce2c5fac
|
|
| BLAKE2b-256 |
b495a996bfd38644c1e1a88d807adaa25bc3532692c52b42cd60a3ea840a17df
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f6f336851bd7815d4ed761ab5be643944943b145bb60d9038228912322d0d72
|
|
| MD5 |
4c1142e875109799884bfeddb3745c4a
|
|
| BLAKE2b-256 |
9c277e9eb107f1ee1209710ae3616b078584431facd89d301e6c807491c2aceb
|