Python SDK
Python SDK v0.0.29
The OpenPay Python SDK (getopenpay
) enables developers to seamlessly integrate OpenPay into Python applications. It provides straightforward, intuitive classes that abstract HTTP requests, handle request formatting, and parse responses from the OpenPay API.
This guide walks you through integrating OpenPay using Python.
Installation
Install via pip:
pip install getopenpay
SDK architecture
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
Initialize the SDK
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"
)
Examples
Create a customer
created_customer = client.customers.create({
"email": "opemipo@disu.com"
})
The result contains customer_id
, which you’ll use for subscriptions or checkouts.
Create a subscription
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.
List subscriptions
subscriptions = client.subscriptions.list()
Returns a list of subscriptions associated with your account.
Create a payment link
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"]
.
Create a checkout session
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 errors
All errors raise OpenPayException
.
from getopenpay.exceptions import OpenPayException
try:
client.customers.retrieve("invalid_id")
except OpenPayException as e:
print("Error:", e)
Notes on usage
-
Every method accepts a
dict
and returns adict
-
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
)
Reference
-
Other SDKs:
In this directory, you'll find OpenPay's official SDKs designed to simplify your integration with our APIs.