Recurly Python Client

4.70.0 · active · verified Thu Apr 16

The `recurly` library is the official Python client for Recurly's V3 API, enabling developers to integrate subscription billing and management into their applications. It provides functionalities for managing accounts, subscriptions, invoices, and transactions. The library is actively maintained with frequent minor version releases, often driven by updates to the underlying Recurly API schema, and the current stable version is 4.70.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Recurly client using an API key and perform a basic API call to retrieve an account and list its invoices. Ensure `RECURLY_API_KEY` is set as an environment variable or replaced with your actual private API key. Remember to handle `recurly.ApiError` for API-specific responses and `recurly.NetworkError` for connectivity issues.

import os
import recurly

# It's highly recommended to store your API key as an environment variable.
RECURLY_API_KEY = os.environ.get('RECURLY_API_KEY', 'YOUR_PRIVATE_API_KEY')

# Initialize the Recurly client
# For EU region, use: client = recurly.Client(RECURLY_API_KEY, region='eu')
client = recurly.Client(RECURLY_API_KEY)

# Example: Fetch an account by its code
try:
    # Note: Use 'code-' prefix for account codes, if applicable, based on your Recurly setup.
    account_code = 'code-example-account-123'
    account = client.get_account(account_code=account_code)
    print(f"Successfully retrieved account: {account.id} (Code: {account.code}, Email: {account.email})")

    # Example: List recent invoices for the account
    print(f"\nRecent invoices for account {account.code}:")
    for invoice in client.list_account_invoices(account_id=account.id).items():
        print(f"  Invoice {invoice.id}: State={invoice.state}, Total={invoice.total}")

except recurly.ApiError as e:
    print(f"Recurly API Error: {e.message}")
    if e.error_code:
        print(f"  Error Code: {e.error_code}, Details: {e.details}")
except recurly.NetworkError as e:
    print(f"Recurly Network Error: {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →