Python SDK Initialization


Class Initialization sets up the PhonePe Python SDK client using your credentials. This step creates a single client instance that handles all API communications securely throughout the application runtime.

  • The StandardCheckoutClient class is used to interact with PhonePe APIs. Only one instance of this client should be created per runtime. Make sure to use the correct credentials when initializing to avoid exceptions.
Parameter NameData TypeMandatory
(Yes/No)
Default ValueDescription
client_idStringYesYour unique client ID for secure communication with PhonePe.
client_versionIntegerYesClient version for secure communication with PhonePe.
client_secretStringYesSecret key provided by PhonePe Payment Gateway, which must be securely stored.
envEnumYesEnvironment for the client:
• PRODUCTION
• SANDBOX
pool_sizeintNo10Max pooled (kept-alive) connections per host. Low-traffic merchants can use 2–4; high-concurrency merchants should raise it.
keep_alive_secondsfloatNo60A pooled connection idle longer than this is closed and replaced before it is reused, so a connection silently dropped by the network is never handed to a request.
connect_timeout_secondsfloatNo3Max time to establish the TCP/TLS connection.
read_timeout_secondsfloatNo30Max time to wait for a response after the request is sent.
pool_blockboolNoTRUEWhen all pooled connections are busy, wait for one to free up instead of opening a throwaway connection outside the pool.
Code Reference
from phonepe.sdk.pg.common.configs.http_client_config import HttpClientConfig
from phonepe.sdk.pg.payments.v2.standard_checkout_client import StandardCheckoutClient
from phonepe.sdk.pg.env import Env

http_client_config = HttpClientConfig(
    pool_size=10,               # max pooled (kept-alive) connections per host
    keep_alive_seconds=60,      # proactively recycle connections idle longer than this
    connect_timeout_seconds=3,  # max time to establish the TCP/TLS connection
    read_timeout_seconds=30,    # max time to wait for a response once the request is sent
    pool_block=True,            # wait for a free pooled connection instead of overflowing the pool
)

client = StandardCheckoutClient.get_instance(
    client_id=client_id,
    client_secret=client_secret,
    client_version=client_version,
    env=env,
    http_client_config=http_client_config,   # optional
)

Now that you’ve learned how to initialize the StandardCheckoutClient with your credentials to connect securely with PhonePe APIs. Next, you’ll create a payment request to start the transaction and generate the payment link for users.

Head over to Initiate Payment to learn how to start the transaction.

Is this article helpful?