A Python wrapper for the Paddle Billing API
Reason this release was yanked:
Deprecated. Use paddle-python-sdk
Project description
paddle-billing-python-sdk
A Python wrapper for the new Paddle Billing SDK, based on Paddle's official paddle-php-sdk
Core developers
Table of contents
Requirements
Python>=3.11 (for native type hinting, StrEnum, trailing commas, f-strings)
Project dependencies (automatically installed by pip):
- requests>=2.31
- urllib3>=2.1.0
Install
Because paddle-billing-python-sdk
is available on PyPi, installation is as simple as running the following pip
command:
pip install paddle-billing-python-sdk
Usage
To authenticate, you'll need an API key. You can create and manage API keys in Paddle > Developer tools > Authentication.
Pass your API key while initializing a new Paddle client:
from paddle_billing import Client
paddle = Client('PADDLE_API_SECRET_KEY')
You can pass your Paddle API secret key into the SDK from an environment variable:
from os import getenv
from paddle_billing import Client
paddle = Client(getenv('PADDLE_API_SECRET_KEY'))
You can also pass an environment to work with Paddle's sandbox:
from paddle_billing import Client, Environment, Options
paddle = Client('PADDLE_API_SECRET_KEY', options=Options(Environment.SANDBOX))
Keep in mind that API keys are separate for your sandbox and live accounts, so you'll need to generate keys for each environment.
Examples
There are examples included in the examples folder. To prevent leaking errors we recommend encapsulating Paddle operations inside Try/Except blocks. For brevity, most of the examples below do not do this.
List entities
You can list supported entities with the list()
method in the resource. It returns an iterator to help when working with multiple pages.
from paddle_billing import Client
paddle = Client('PADDLE_API_SECRET_KEY')
products = paddle.products.list()
# list() returns an iterable, so pagination is automatically handled
for product in products:
print(f"Product's id: {product.id}")
Get an entity
You can get an entity with the get()
method in the resource. It accepts the id
of the entity to get. The entity is returned.
from paddle_billing import Client
paddle = Client('PADDLE_API_SECRET_KEY')
product = paddle.products.get('PRODUCT_ID')
Create an entity
You can create a supported entity with the create()
method in the resource. It accepts the resource's corresponding CreateOperation
e.g. CreateProduct
. The created entity is returned.
from paddle_billing import Client
from paddle_billing.Entities.Shared.TaxCategory import TaxCategory
from paddle_billing.Resources.Products.Operations import CreateProduct
paddle = Client('PADDLE_API_SECRET_KEY')
created_product = paddle.products.create(CreateProduct(
name = 'My Product',
tax_category = TaxCategory.Standard,
))
Update an entity
You can update a supported entity with the update()
method in the resource. It accepts the id
of the entity to update and the corresponding UpdateOperation
e.g. UpdateProduct
. The updated entity is returned.
from paddle_billing import Client
from paddle_billing.Resources.Products.Operations import UpdateProduct
paddle = Client('PADDLE_API_SECRET_KEY')
# Update the name of the product
updated_product = paddle.products.update('PRODUCT_ID', UpdateProduct(
name = 'My Improved Product'
))
Where operations require more than one id
, the update()
method accepts multiple arguments. For example, to update an address for a customer, pass the customerId
and the addressId
:
updated_address = paddle.addresses.update(
'CUSTOMER_ID',
'ADDRESS_ID',
operation_goes_here,
)
Delete an entity
You can delete an entity with the delete()
method in the resource. It accepts the id
of the entity to delete. The deleted entity is returned.
from paddle_billing import Client
paddle = Client('PADDLE_API_SECRET_KEY')
deleted_product = paddle.products.delete('PRODUCT_ID')
Resources
Webhook signature verification
The SDK includes a helper class to verify webhook signatures sent by Notifications from Paddle.
from paddle_billing.Notifications import Secret, Verifier
integrity_check = Verifier().verify(request, Secret('WEBHOOK_SECRET_KEY')
Learn more
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
Hashes for paddle-billing-python-sdk-0.1.0b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405b243f2f0e8ec58cdd525ac65802e88437f79fce8b0f8a41830aef39c87e48 |
|
MD5 | 500be9af4b9d0b6e68dec4d797a340de |
|
BLAKE2b-256 | 05537d692b442dfd3c996959735887dca6657b21a1f4be2112532db16a06575e |
Hashes for paddle_billing_python_sdk-0.1.0b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 780f1e8fb64ea45a21ea0d5f10788e78425343e9d0a6d75756b92c778e718f68 |
|
MD5 | c5f31d59878dce8628606c8ac3724823 |
|
BLAKE2b-256 | 1da071904721672b46ece593efb543aafa6c2997d371c4b3d6b5666846d13281 |