Registry / payments / phonepe_sdk

phonepe_sdk

JSON →
librarylatest (from PhonePe registry)pypypiunverified

Official PhonePe Payment Gateway Python SDK. NOT on PyPI — must install from PhonePe's private registry using a special pip command. TWO packages cause confusion: 'phonepe' on PyPI (1.0.1) is a community wrapper using old v1 API — NOT the official SDK. Official SDK is 'phonepe_sdk' from phonepe.mycloudrepo.io. Amount in paise (1 INR = 100 paise). Client must be initialized only ONCE — reinitializing raises PhonePeException. Mandatory status check polling after payment.

payments
pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk
Install & Compatibility
Where this runs
tested against v2.1.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 10.47s
py 3.11
✓ —
✓ 10.57s
py 3.12
3/5 runs
3/5 runs
py 3.13
3/5 runs
3/5 runs
py 3.9
✓ —
✓ 10.8s
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StandardCheckoutClient
from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient from phonepe.sdk.pg.payments.v2.models.request.standard_checkout_pay_request import StandardCheckoutPayRequest from phonepe.sdk.pg.env import Env import uuid # Initialize ONCE — reinitializing raises PhonePeException client = StandardCheckoutClient( client_id='<client_id>', client_secret='<client_secret>', client_version=1, env=Env.SANDBOX # or Env.PRODUCTION ) # Create payment order_id = str(uuid.uuid4()) request = StandardCheckoutPayRequest.build_request( merchant_order_id=order_id, amount=10000, # 100 INR in paise redirect_url='https://yourapp.com/callback' ) response = client.pay(request) print(response.redirect_url) # redirect user here
# Wrong: community package from PyPI — not official from phonepe import PhonePe phonepe = PhonePe('MERCHANT_ID', 'SALT', 'HOST', 'REDIRECT', 'WEBHOOK') # Wrong: pip install phonepe (wrong package) # Wrong: reinitializing client client1 = StandardCheckoutClient(...) client2 = StandardCheckoutClient(...) # raises PhonePeException
Official SDK is NOT on PyPI. 'pip install phonepe' installs community wrapper using old v1 API. Official install requires --index-url flag pointing to PhonePe's registry.

PhonePe Python SDK — payment creation and status check.

# Install from PhonePe registry (NOT PyPI): # pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient from phonepe.sdk.pg.payments.v2.models.request.standard_checkout_pay_request import StandardCheckoutPayRequest from phonepe.sdk.pg.env import Env import uuid # Initialize once at app startup client = StandardCheckoutClient( client_id='<client_id>', # from PhonePe dashboard client_secret='<client_secret>', client_version=1, env=Env.SANDBOX ) # Create payment order_id = str(uuid.uuid4()) request = StandardCheckoutPayRequest.build_request( merchant_order_id=order_id, amount=50000, # 500 INR in paise redirect_url=f'https://yourapp.com/callback?order_id={order_id}' ) response = client.pay(request) # Redirect user to response.redirect_url print('Redirect to:', response.redirect_url) # After redirect, check status (mandatory) status = client.get_order_status(merchant_order_id=order_id) print('Payment state:', status.state) # COMPLETED, FAILED, PENDING
Debug
Known issues
breakingOfficial PhonePe SDK is NOT on PyPI. 'pip install phonepe_sdk' alone fails. Must use --index-url pointing to PhonePe's private registry.
fix
pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk
affects: all
breaking'phonepe' on PyPI (1.0.1) is a community package using old PhonePe v1 API — NOT the official SDK. Using it risks API deprecation and lacks official support.
fix
Use official phonepe_sdk from PhonePe's registry, not 'pip install phonepe' from PyPI.
affects: all
breakingStandardCheckoutClient must be initialized ONLY ONCE per application. Reinitializing raises PhonePeException.
fix
Initialize at app startup as a singleton. Use dependency injection or module-level variable.
affects: all
breakingAmount is in paise (1 INR = 100 paise) — same as Razorpay. 500 INR = 50000 paise. Passing rupees directly will undercharge.
fix
amount_in_paise = amount_in_inr * 100
affects: all
gotchaStatus check after payment is MANDATORY. PhonePe docs require polling get_order_status() after redirect — do not rely on redirect callback alone.
fix
Always call client.get_order_status(merchant_order_id=order_id) after redirect to confirm payment state.
affects: all
gotchaSANDBOX uses test credentials from PhonePe merchant dashboard. Sandbox and Production have different client_id/secret pairs.
fix
Use Env.SANDBOX with sandbox credentials for testing. Switch to Env.PRODUCTION with live credentials for deployment.
affects: all
breakingModuleNotFoundError: No module named 'pkg_resources' occurs when the 'setuptools' package is not installed. This module is a dependency of 'apscheduler', which the PhonePe SDK utilizes.
fix
Ensure 'setuptools' is installed in your environment (e.g., by running `pip install setuptools`). In Docker environments based on minimal images like Alpine, you might need to explicitly add this to your Dockerfile.
affects: all
Upgrade
Version history
latest (from PhonePe registry)latest on PyPI
Audit
Dependencies
requestsrequiredRequired. Installed automatically.
Agent activity
94 hits · last 30 days
node
20
seranking-bot
4
ahrefsbot
2
bytedance
2
Amazon
1
OpenAI (training)
1
Resources