Python SDK

The OpenPay Python SDK (getopenpay) helps developers integrate OpenPay into Python applications with ease. It offers simple, intuitive classes for interacting with OpenPay’s API, abstracting HTTP calls, request shaping, and response parsing.

This guide shows you how to integrate OpenPay using Python.

InstallationCopied!

Install via pip:

pip install getopenpay 

SDK ArchitectureCopied!

The OpenPay SDK exposes:

  • A main OpenPay class for API key configuration

  • Resource-specific APIs like:

    • customers

    • subscriptions

    • payment_links

    • checkout

  • All methods accept and return standard Python dictionaries

Step 1: Initialize the SDKCopied!

You must create an instance of OpenPay with your API key:

from getopenpay import OpenPay

client = OpenPay(api_key="sk_test_abc123")

You can also configure a custom API base (e.g., for staging):

client = OpenPay(
    api_key="sk_test_abc123",
    base_url="https://connto.getopenpay.com"
)

Example: Create a CustomerCopied!

created_customer = client.customers.create({
    "email": "opemipo@disu.com"
})

The result contains customer_id, which you’ll use for subscriptions or checkouts.

📅 Example: Create a SubscriptionCopied!

created_subscription = client.subscriptions.create({
    "customer_id": "cus_abc123",
    "price_id": "price_xyz456"
})

Ensure that price_id and customer_id refer to real resources. Prices are typically created via the OpenPay dashboard or Prices API.

Example: List SubscriptionsCopied!

subscriptions = client.subscriptions.list()

Returns a list of subscriptions associated with your account.

payment_link = client.payment_links.create({
    "amount": 1000,
    "currency": "usd",
    "description": "Consulting session",
    "redirect_url": "https://yourapp.com/thanks"
})

You can embed or email the returned payment_link["url"].

Example: Create a Checkout SessionCopied!

checkout = client.checkout.create_session({
    "customer_id": "cus_abc123",
    "price_id": "price_xyz456"
})

To validate a session:

client.checkout.validate_session(checkout_attempt_id="checkout_abc123")

Handling ErrorsCopied!

All errors raise OpenPayException.

from getopenpay.exceptions import OpenPayException

try:
    client.customers.retrieve("invalid_id")
except OpenPayException as e:
    print("Error:", e)

Notes on UsageCopied!

  • Every method accepts a dict and returns a dict

  • SDK methods map 1:1 to OpenPay’s REST API endpoints

  • Some methods may require required fields to be explicitly present (e.g. price_id, customer_id)

📚 Want More?Copied!