Cashfree Payment Gateway Python SDK
Official Cashfree Payment Gateway Python SDK. Current version: 5.0.6 (Mar 2026). THREE packages on PyPI causing confusion: 'cashfree-sdk' (0.1.3 — beta, NOT recommended for production by Cashfree), 'cashfree_pg' (5.0.6 — correct current PG SDK), 'cashfree' (1.0.1 — unrelated package). Use cashfree_pg. API version string must be passed to every API call. Supports SANDBOX and PRODUCTION environments. Amount in rupees (float) — unlike Razorpay which uses paise.
Warnings
- breaking Three packages on PyPI: cashfree-sdk (beta/not for production), cashfree_pg (correct SDK), cashfree (unrelated). LLMs and old tutorials reference cashfree-sdk which Cashfree explicitly says is not for production.
- breaking x_api_version string must be passed to every API call. Omitting it raises TypeError. Unlike Razorpay which doesn't require API version per call.
- gotcha Amount is in RUPEES (float) — not paise. Unlike Razorpay which uses paise. 500 means ₹500. This is the opposite of Razorpay's convention.
- gotcha SANDBOX environment uses TEST keys from Cashfree dashboard. Test client IDs start with 'TEST_'. Production keys are different — switch XEnvironment=Cashfree.PRODUCTION with live keys.
- gotcha return_url in OrderMeta must include {order_id} placeholder — Cashfree replaces it with actual order ID. Missing placeholder means you can't identify which order was paid.
- gotcha IP whitelisting required for production. Cashfree blocks API calls from non-whitelisted IPs in production. Add your server IP in Cashfree dashboard under Security settings.
Install
-
pip install cashfree_pg
Imports
- Cashfree PG client + order creation
from cashfree_pg.models.create_order_request import CreateOrderRequest from cashfree_pg.api_client import Cashfree from cashfree_pg.models.customer_details import CustomerDetails from cashfree_pg.models.order_meta import OrderMeta cashfree = Cashfree( XEnvironment=Cashfree.SANDBOX, # or Cashfree.PRODUCTION XClientId='<x-client-id>', XClientSecret='<x-client-secret>' ) x_api_version = '2023-08-01' # required for every call customer = CustomerDetails( customer_id='cust_001', customer_phone='9999999999' ) order_meta = OrderMeta( return_url='https://yourapp.com/payment/callback?order_id={order_id}' ) create_request = CreateOrderRequest( order_amount=500.00, # in rupees (not paise) order_currency='INR', customer_details=customer, order_meta=order_meta ) response = cashfree.PGCreateOrder(x_api_version, create_request, None, None) print(response.data.order_id)
Quickstart
# pip install cashfree_pg
from cashfree_pg.api_client import Cashfree
from cashfree_pg.models.create_order_request import CreateOrderRequest
from cashfree_pg.models.customer_details import CustomerDetails
from cashfree_pg.models.order_meta import OrderMeta
# Initialize — get keys from dashboard.cashfree.com
cashfree = Cashfree(
XEnvironment=Cashfree.SANDBOX,
XClientId='TEST_APP_ID',
XClientSecret='TEST_SECRET_KEY'
)
x_api_version = '2023-08-01' # pass to every API call
# Create order
customer = CustomerDetails(customer_id='cust_001', customer_phone='9999999999')
meta = OrderMeta(return_url='https://yourapp.com/callback?order_id={order_id}')
request = CreateOrderRequest(
order_amount=499.00, # rupees, not paise
order_currency='INR',
customer_details=customer,
order_meta=meta
)
try:
response = cashfree.PGCreateOrder(x_api_version, request, None, None)
print('Order ID:', response.data.order_id)
print('Payment URL:', response.data.payment_link)
except Exception as e:
print('Error:', e)
# Fetch order status
try:
order = cashfree.PGFetchOrder(x_api_version, response.data.order_id, None)
print('Status:', order.data.order_status)
except Exception as e:
print('Error:', e)