Official Python SDK for OpenPay
Project description
Openpay Python Library
The Openpay Python library provides convenient access to the Openpay API from Python.
Documentation
API reference documentation is available here.
Installation
pip install getopenpay
Usage
Instantiate and use the client with the following:
from openpay import SelectedPriceQuantity
from openpay.client import OpenPay
client = OpenPay(
token="YOUR_TOKEN",
)
client.subscriptions.create(
customer_id="cus_dev_abc123",
payment_method_id="cc_dev_abc123",
selected_product_price_quantity=[
SelectedPriceQuantity(
price_id="price_dev_abc123",
quantity=2,
)
],
total_amount_atom=9000,
)
Async Client
The SDK also exports an async
client so that you can make non-blocking calls to our API.
import asyncio
from openpay import SelectedPriceQuantity
from openpay.client import AsyncOpenPay
client = AsyncOpenPay(
token="YOUR_TOKEN",
)
async def main() -> None:
await client.subscriptions.create(
customer_id="cus_dev_abc123",
payment_method_id="cc_dev_abc123",
selected_product_price_quantity=[
SelectedPriceQuantity(
price_id="price_dev_abc123",
quantity=2,
)
],
total_amount_atom=9000,
)
asyncio.run(main())
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
from .api_error import ApiError
try:
client.subscriptions.create(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Pagination
Paginated requests will return a SyncPager
or AsyncPager
, which can be used as generators for the underlying object.
from openpay.client import OpenPay
client = OpenPay(
token="YOUR_TOKEN",
)
response = client.charges.list()
for item in response:
yield item
# alternatively, you can paginate page-by-page
for page in response.iter_pages():
yield page
Advanced
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retriable when any of the following HTTP status codes is returned:
Use the max_retries
request option to configure this behavior.
client.subscriptions.create(...,{
max_retries=1
})
Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
from openpay.client import OpenPay
client = OpenPay(..., { timeout=20.0 }, )
# Override timeout for a specific method
client.subscriptions.create(...,{
timeout_in_seconds=1
})
Custom Client
You can override the httpx
client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
import httpx
from openpay.client import OpenPay
client = OpenPay(
...,
http_client=httpx.Client(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file getopenpay-1.0.0b0.tar.gz
.
File metadata
- Download URL: getopenpay-1.0.0b0.tar.gz
- Upload date:
- Size: 90.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1067-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 875bbe880e77cfe7f56fbefd04b3cfa292e634ff6f80223143022d2b67749271 |
|
MD5 | e3422dc3332265227d681e0b656c26d7 |
|
BLAKE2b-256 | f4a8c916b4dd41fa8c80fa77005cbcef77ba3c6894f47cf27118836ea0397d66 |
File details
Details for the file getopenpay-1.0.0b0-py3-none-any.whl
.
File metadata
- Download URL: getopenpay-1.0.0b0-py3-none-any.whl
- Upload date:
- Size: 215.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1067-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 073957eac3b4a189c0a9bcd713ce34b65d039c9509e96efcf3897dbb984013b0 |
|
MD5 | 89567d097954293eac49f83710fe3c4e |
|
BLAKE2b-256 | c727df6a2d1f063be62117b3f509315f372011bcd2c2a87d496fa2c86a2c004f |