Braintree Python SDK
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
- breaking SSL certificate update: Braintree updated root SSL cert April 2024. SDK versions older than ~4.33.0 will stop working after March 30, 2026. Update to latest version.
- gotcha Amount must be a string ('100.00'), not float or int. Passing a number raises an error or causes unexpected behavior.
- gotcha Without submit_for_settlement: True, transactions are only authorized — not captured. Funds are not collected. Must explicitly settle.
- gotcha result.is_success being False doesn't always mean total failure — check result.transaction for processor decline (card declined) vs result.errors for validation errors.
Install
-
pip install braintree
Imports
- BraintreeGateway
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' ) ) # Generate client token — send to frontend client_token = gateway.client_token.generate() # Create transaction with nonce from frontend result = gateway.transaction.sale({ 'amount': '100.00', # string, not float 'payment_method_nonce': nonce_from_client, 'options': { 'submit_for_settlement': True # capture immediately } }) if result.is_success: print(result.transaction.id) else: for error in result.errors.deep_errors: print(error.message)
Quickstart
# 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)