Typing Stubs for Braintree

4.42.0.20260408 · active · verified Fri Apr 17

This package provides static type checking stubs for the `braintree` Python SDK. It allows tools like Mypy and Pylance to validate type usage in your Braintree integration code, improving code quality and catching potential errors before runtime. It's maintained as part of the `typeshed` project and is updated regularly to reflect changes in the official `braintree` library. The current version is `4.42.0.20260408`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure the Braintree gateway using environment variables and generate a client token. This code uses the actual `braintree` library; `types-braintree` merely provides static type checking for this code.

import braintree
import os

# Configure Braintree Gateway using environment variables for security
gateway = braintree.BraintreeGateway(
    braintree.Configuration(
        environment=os.environ.get('BRAINTREE_ENVIRONMENT', braintree.Environment.Sandbox),
        merchant_id=os.environ.get('BRAINTREE_MERCHANT_ID', 'your_sandbox_merchant_id'),
        public_key=os.environ.get('BRAINTREE_PUBLIC_KEY', 'your_sandbox_public_key'),
        private_key=os.environ.get('BRAINTREE_PRIVATE_KEY', 'your_sandbox_private_key')
    )
)

# Example: Generate a client token (common for web/mobile integrations)
try:
    client_token = gateway.client_token.generate({})
    print(f"Generated Client Token: {client_token}")
except Exception as e:
    print(f"Error generating client token: {e}")

view raw JSON →