Skip to main content
Python SDK, Python applications को Dodo Payments REST API तक typed access देता है। इसमें एक synchronous client, DodoPayments, और एक asynchronous client, AsyncDodoPayments है, जो दोनों httpx पर बनाए गए हैं। Nested request parameters typed dictionaries होते हैं और responses Pydantic models होते हैं।

स्थापना

SDK को pip से install करें:
async client के लिए aiohttp को HTTP backend के रूप में उपयोग करने हेतु, aiohttp extra install करें:
client.webhooks.unwrap() से webhook signatures verify करने के लिए, webhooks extra भी install करें: pip install "dodopayments[webhooks]"।
SDK के लिए Python 3.9 या बाद का version आवश्यक है। Security updates पाने के लिए नवीनतम stable Python release का उपयोग करें।

त्वरित शुरुआत

Synchronous Client

एक client बनाएं, फिर checkout session बनाएं:
यदि आप bearer_token को छोड़ देते हैं, तो client DODO_PAYMENTS_API_KEY environment variable को पढ़ता है। यदि आप environment को छोड़ देते हैं, तो client live mode से connect होता है। Test mode API key केवल environment="test_mode" के साथ काम करती है।

Asynchronous Client

AsyncDodoPayments में DodoPayments जैसी ही methods हैं। प्रत्येक call को await करें:
API keys को environment variables या secrets manager में रखें। उन्हें version control में कभी commit न करें।

मुख्य सुविधाएं

Pythonic Interface

Parameters के लिए keyword arguments, nested objects के लिए TypedDict types, और responses के लिए Pydantic models।

Async/Await

asyncio के लिए AsyncDodoPayments, जिसमें aiohttp एक optional HTTP backend है।

Type Hints

प्रत्येक method पर type hints, editor autocomplete और mypy के साथ type checking के लिए।

Auto-Pagination

List methods ऐसे iterators लौटाती हैं जो loop करते समय अगला page fetch करते हैं।

Configuration

Environment Variables

अपनी API key को environment variable में रखें:
.env
जब आप matching argument pass नहीं करते, तब client इन variables को पढ़ता है: यदि DODO_PAYMENTS_BASE_URL set है और आप environment भी pass करते हैं, तो constructor “Ambiguous URL” error उत्पन्न करता है। उस स्थिति में environment का उपयोग करने के लिए base_url=None pass करें। Webhook verify करने के लिए raw request body और headers को client.webhooks.unwrap(payload, headers=headers) में pass करें। यह आपकी webhook key से signature check करता है और parsed event लौटाता है। client.webhooks.unsafe_unwrap(payload) body को verify किए बिना parse करता है, इसलिए इसका उपयोग केवल testing के लिए करें। Webhooks देखें।

Timeouts

Requests default रूप से 1 minute बाद timeout हो जाती हैं और connection timeout 5 seconds होता है। Seconds में timeout pass करें, या अलग-अलग read, write और connect limits के लिए एक httpx.Timeout pass करें:
जब कोई request timeout होती है, तो SDK APITimeoutError उत्पन्न करता है। Timed-out requests को retry किया जाता है, इसलिए fail होने से पहले कोई call timeout से अधिक समय ले सकती है।

Retries

Client पर max_retries set करें, या किसी एक request पर with_options() के साथ set करें:
SDK connection errors और status 408, 409, 429 या 500 और उससे ऊपर वाले responses को retry करता है। Default रूप से यह exponential backoff के साथ दो बार retry करता है। जब कोई request फिर भी fail होती है, तो SDK dodopayments.APIError की subclass उत्पन्न करता है: Status exceptions dodopayments.APIStatusError से inherit करती हैं, जिसमें status_code और response attributes होते हैं। APITimeoutError, APIConnectionError की subclass है।

सामान्य Operations

इस section में दिए गए examples Quick Start के client का उपयोग करते हैं।

Checkout Session बनाएं

एक checkout session बनाएं, फिर customer को लौटाए गए checkout_url पर redirect करें:
प्रत्येक checkout_url केवल एक बार काम करता है और 24 hours बाद expire हो जाता है। प्रत्येक session option के लिए Checkout Sessions देखें।

Customers Manage करें

Email address और name के साथ customer बनाएं, फिर उसे ID से retrieve करें:

Subscriptions Handle करें

एक subscription बनाएं, on-demand subscription को charge करें और subscription का usage history पढ़ें।
POST /subscriptions (SDK की subscriptions.create method) deprecated है। यह मौजूदा integrations के लिए अभी भी काम करती है, लेकिन नए integrations को Checkout Session के माध्यम से subscriptions बनानी चाहिए।
billing के लिए केवल country आवश्यक है, जो दो-अक्षरों वाला ISO country code है। customer किसी existing customer को attach करने के लिए {"customer_id": ...} या नया customer बनाने के लिए {"email": ..., "name": ...} लेता है। charge on-demand subscriptions के लिए है और product_price currency की smallest unit में होता है। retrieve_usage_history paginated list लौटाता है, जिसे आप Pagination में दिखाए अनुसार iterate कर सकते हैं।

Usage-Based Billing

Usage Events Ingest करें

किसी customer के लिए usage events भेजें:
event_id idempotency key है, इसलिए प्रत्येक event को unique value दें। यदि एक ही request में वही event_id दो बार दिखाई देता है, तो पूरी request reject कर दी जाती है। यदि कोई event_id पहले ही ingest किया जा चुका है, तो नया event ignore कर दिया जाता है। एक request में अधिकतम 1,000 events स्वीकार किए जाते हैं। timestamp default रूप से current time पर set होता है और यदि वह past में 1 hour से अधिक या future में 5 minutes से अधिक हो, तो reject कर दिया जाता है।

Events List और Retrieve करें

किसी event को उसके event_id से retrieve करें, या customer और event name से filtered events की list बनाएं:
usage_events.list, meter_id, start और end filters भी स्वीकार करता है।

Pagination

Auto-Pagination

List methods ऐसा iterator लौटाती हैं जो loop करते समय अगला page fetch करता है:

Async Pagination

Async client के साथ async for का उपयोग करके loop करें:

Manual Pagination

एक समय में एक page के साथ काम करने के लिए items पढ़ें और has_next_page() तथा get_next_page() call करें। next_page_info() अगली request के parameters लौटाता है:

HTTP Client Configuration

Proxy, custom transport या अन्य httpx settings जोड़ने के लिए अपना http_client pass करें। DefaultHttpxClient SDK की default connection limits, timeout और redirect settings बनाए रखता है:
किसी एक request के लिए अलग HTTP client का उपयोग करने हेतु client.with_options(http_client=...) call करें।

AIOHTTP के साथ Async

Default रूप से async client httpx के साथ requests भेजता है। बेहतर concurrency के लिए aiohttp extra install करें और DefaultAioHttpClient() को http_client के रूप में pass करें:

Logging

SDK standard library के logging module के साथ logs करता है। Logging चालू करने के लिए DODO_PAYMENTS_LOG को info पर set करें:
अधिक विवरण के लिए इसे debug पर set करें:

Framework Integration

ये examples किसी web endpoint से checkout session बनाते हैं और उसका URL लौटाते हैं।

FastAPI

यह endpoint async client का उपयोग करता है:

Django

यह view sync client का उपयोग करता है:

Resources

GitHub Repository

Source code, releases और methods की पूरी list।

API Reference

प्रत्येक endpoint, parameter और response।

Discord Community

प्रश्न पूछें और अन्य developers से बातचीत करें।

Report Issues

Bugs report करें या features का अनुरोध करें।

Support

Python SDK के लिए सहायता पाने हेतु:

Contributing

योगदान करने के लिए contributing guidelines पढ़ें।
अंतिम संशोधन 26 सितंबर 2026