GoCardless Pro Python Client Library

3.3.0 · active · verified Thu Apr 16

A client library for the GoCardless Pro API. It simplifies integration with the GoCardless platform, handling API requests, authentication, and error handling. As of version 3.3.0, it is actively maintained with regular updates, supporting Python 3.9, 3.10, 3.11, and 3.12.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the GoCardless Pro client using an access token and environment, then demonstrates creating a customer and listing existing payments. Remember to set `GOCARDLESS_ACCESS_TOKEN` and `GOCARDLESS_ENVIRONMENT` (e.g., 'sandbox' or 'live') in your environment variables.

import os
from gocardless_pro import Client

# Ensure ACCESS_TOKEN and ENVIRONMENT are set in your environment variables
access_token = os.environ.get('GOCARDLESS_ACCESS_TOKEN', 'YOUR_GOCARDLESS_ACCESS_TOKEN')
environment = os.environ.get('GOCARDLESS_ENVIRONMENT', 'sandbox') # or 'live'

if not access_token or access_token == 'YOUR_GOCARDLESS_ACCESS_TOKEN':
    raise ValueError("Please set the GOCARDLESS_ACCESS_TOKEN environment variable or replace the placeholder.")

client = Client(access_token=access_token, environment=environment)

try:
    # Create a new customer
    customer = client.customers.create(
        params={'email': 'jane.doe@example.com', 'given_name': 'Jane', 'family_name': 'Doe'}
    )
    print(f"Created customer: {customer.id} - {customer.email}")

    # List payments (demonstrates fetching data)
    payments_list = client.payments.list()
    print(f"\nFirst 5 payments (total: {len(payments_list.records)}):")
    for i, payment in enumerate(payments_list.records[:5]):
        print(f"  - Payment ID: {payment.id}, Amount: {payment.amount}, Currency: {payment.currency}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →