The `alipay-sdk-python` library is the official Python SDK for integrating with Alipay's Open Platform APIs. It provides functionalities for various payment scenarios, including web, app, and QR code payments, as well as refund, query, and notification processing. Maintained by Alipay, it receives regular updates, typically several times a month, reflecting API changes and improvements. The current version is 3.7.1098.
pip install alipay-sdk-pythonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Alipay client and create a basic web page payment request. It configures the client with essential keys and a sandbox server URL, then constructs a `AlipayTradePagePayRequest` to generate an HTML form string for redirecting the user to Alipay for payment. Remember to replace placeholder keys with your actual Alipay developer credentials and adjust the `server_url` for production.
Update your import paths and client initialization logic to match the 3.x API. Refer to the official documentation or the quickstart for the correct patterns.
Ensure your `app_private_key` value is a plain string containing only the base64 encoded private key material. For example, if you have a key file, open it, copy only the content between `BEGIN` and `END` lines, and remove all newlines.
Verify that `alipay_client_config.server_url` points to the correct environment (`https://openapi.alipaydev.com/gateway.do` for sandbox, `https://openapi.alipay.com/gateway.do` for production) and that the corresponding `app_id`, `app_private_key`, and `alipay_public_key` are valid for that environment.
Always use the SDK's built-in signature verification utility (e.g., `alipay_client.verify_notification`) when processing `notify_url` callbacks. Do not manually parse or trust notification data without verification.
Update your imports to use the new package structure, primarily `from alipay.aop.api.DefaultAlipayClient import DefaultAlipayClient` and `from alipay.aop.api.AlipayClientConfig import AlipayClientConfig`. Refer to the quickstart example.
Double-check your `APP_ID`, `APP_PRIVATE_KEY`, and `ALIPAY_PUBLIC_KEY` in your configuration. Ensure the private key is in PKCS8 format without headers/footers. Also, confirm you are using the correct keys for the specified Alipay environment (sandbox vs. production).
Ensure that `alipay_client_config.app_id` is set to your actual Alipay App ID. Review all required configuration parameters for the `AlipayClientConfig` and for the specific API request you are making, as some `biz_content` fields might also be mandatory.