PhonePe Payment Gateway Python SDK

raw JSON →
latest (from PhonePe registry) verified Tue May 12 auth: no python install: draft quickstart: draft

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.

pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk
error ModuleNotFoundError: No module named 'phonepe_sdk'
cause The official PhonePe SDK (`phonepe_sdk`) was not installed correctly from PhonePe's private registry. Users often try `pip install phonepe_sdk` which fails, or `pip install phonepe` which installs an unofficial community wrapper from PyPI.
fix
Install the official SDK using the designated pip command: pip install --index-url https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-python --extra-index-url https://pypi.org/simple phonepe_sdk
error import phonepe
cause This import statement targets the unofficial `phonepe` package available on PyPI, which is a community wrapper and not the official `phonepe_sdk` from PhonePe's private registry. Using this will lead to `AttributeError` when trying to access official SDK functionalities.
fix
First, uninstall the incorrect PyPI package (pip uninstall phonepe). Then, ensure the official phonepe_sdk is installed using its specific pip install command. Finally, use the correct import path for the official SDK, e.g., from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient.
error PhonePeException: Client already initialized
cause The PhonePe SDK client was attempted to be initialized more than once within the application's lifecycle, which is explicitly prohibited by the SDK's design to prevent re-initialization issues.
fix
Ensure that the PhonePePaymentClient (or StandardCheckoutClient) is initialized only once and that the single instance is reused across all payment-related operations in your application.
breaking Official 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
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.
breaking StandardCheckoutClient 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.
breaking Amount 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
gotcha Status 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.
gotcha SANDBOX 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.
breaking ModuleNotFoundError: 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.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 1.44s 28.9M
3.10 slim (glibc) - - 1.00s 29M
3.11 alpine (musl) - - 1.84s 31.8M
3.11 slim (glibc) - - 1.52s 32M
3.12 alpine (musl) - - - -
3.12 slim (glibc) - - - -
3.13 alpine (musl) - - - -
3.13 slim (glibc) - - - -
3.9 alpine (musl) - - 1.34s 28.2M
3.9 slim (glibc) - - 1.18s 29M

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