Braintree Python SDK

4.42.0 · active · verified Wed Mar 25

PayPal's Braintree payment gateway Python SDK. Current version: 4.42.0 (Mar 2026). Stable API — no major breaking changes from v3 to v4 for Python. SSL certificate update required: Braintree updated root SSL cert April 2024 — SDKs older than ~4.33 will fail after March 2026. Three-step flow: generate client token server-side → collect payment method nonce client-side → create transaction server-side. Amount as string. submit_for_settlement must be True to actually capture funds.

Warnings

Install

Imports

Quickstart

Braintree Python SDK — client token generation and transaction sale.

# pip install braintree
import braintree

gateway = braintree.BraintreeGateway(
    braintree.Configuration(
        environment=braintree.Environment.Sandbox,
        merchant_id='your_merchant_id',
        public_key='your_public_key',
        private_key='your_private_key'
    )
)

# Step 1: Generate client token for frontend
client_token = gateway.client_token.generate()
# Pass client_token to frontend Braintree Drop-in UI

# Step 2: Receive nonce from frontend, create transaction
result = gateway.transaction.sale({
    'amount': '49.99',
    'payment_method_nonce': 'nonce-from-frontend',
    'options': {'submit_for_settlement': True}
})

if result.is_success:
    print('Success:', result.transaction.id)
elif result.transaction:
    print('Processor error:', result.transaction.processor_response_code)
else:
    for err in result.errors.deep_errors:
        print('Validation error:', err.message)

view raw JSON →