Chargebee Python Client Library
The Chargebee Python Client Library is the official Python wrapper for integrating with the Chargebee Subscription Billing API. It provides a comprehensive, idiomatic Python interface to manage customers, subscriptions, invoices, payments, and other billing-related resources. The current version is 3.20.0, and the library is actively maintained with a regular release cadence.
Warnings
- breaking Python Client Library v2 is deprecated and will no longer be supported after December 31, 2025. Users must migrate to v3.x.x to ensure continued support and access to new features.
- breaking Chargebee will rotate TLS certificates with a permanent switch to DigiCert G2 chain by February 2026. Failure to update your environment's trust stores or ensure compatibility might cause API calls to fail with SSL errors.
- gotcha The Chargebee API has two major versions (v1 and v2), and the Python client library has its own versions (v2 and v3). The Python SDK v3 is compatible with the Chargebee API v2. It is crucial to ensure your SDK version is compatible with your Chargebee site's configured API version.
- gotcha All API requests use HTTP Basic Auth where your API key is the username and the password field is left empty. API keys are environment-specific (test vs. live site) and must be kept secure. Do not expose them in client-side code or public repositories.
Install
-
pip install chargebee -
pip install 'chargebee>=3,<4'
Imports
- Chargebee
from chargebee import Chargebee
- Resource Objects (e.g., Customer, Subscription)
response = cb_client.Customer.create(...)
Quickstart
import os
from chargebee import Chargebee
# Configure the Chargebee client with your API key and site name
# It's recommended to use environment variables for sensitive data
API_KEY = os.environ.get('CHARGEBEE_API_KEY', 'your_test_api_key')
SITE_NAME = os.environ.get('CHARGEBEE_SITE_NAME', 'your_test_site')
if API_KEY == 'your_test_api_key' or SITE_NAME == 'your_test_site':
print("WARNING: Please set CHARGEBEE_API_KEY and CHARGEBEE_SITE_NAME environment variables.")
print("Using placeholder values, API calls will likely fail.")
cb_client = Chargebee(api_key=API_KEY, site=SITE_NAME)
try:
# Example: Create a new customer
# Note: CreateParams are nested under the resource class via the client
response = cb_client.Customer.create(
cb_client.Customer.CreateParams(
first_name="John",
last_name="Doe",
email="john.doe@example.com",
locale="en-US"
)
)
customer = response.customer
print(f"Successfully created customer: {customer.id} - {customer.email}")
# Example: Retrieve a customer
# response = cb_client.Customer.retrieve(customer.id)
# retrieved_customer = response.customer
# print(f"Retrieved customer: {retrieved_customer.id} - {retrieved_customer.first_name}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure your API key and site name are correct and have appropriate permissions.")