Braintree Python library
Latest commit 16f70ec Oct 9, 2018
Failed to load latest commit information.
.github 3.38.0 Aug 25, 2017
braintree 3.49.0 Oct 9, 2018
docs 3.29.2 Aug 4, 2016
tests 3.49.0 Oct 9, 2018
.gitignore 2.29.1 May 12, 2014
.pylintrc 3.30.0 Oct 13, 2016 3.31.0 Nov 14, 2016 3.49.0 Oct 9, 2018
Dockerfile 3.40.0 Jan 19, 2018
LICENSE 2.29.1 May 12, 2014 1.0.0 Mar 25, 2010
Makefile 3.40.0 Jan 19, 2018 3.42.0 Feb 28, 2018
Rakefile 3.44.0 Apr 11, 2018 3.25.0 Feb 24, 2016
requirements.txt 3.40.0 Jan 19, 2018
setup.cfg improvements and universal wheels Apr 7, 2017 3.49.0 Oct 9, 2018

Braintree Python library

The Braintree Python library provides integration access to the Braintree Gateway.

Please Note

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, Braintree is updating its services to require TLS 1.2 for all HTTPS connections. Braintree will also require HTTP/1.1 for all connections. Please see our technical documentation for more information.


  • Python 2.6, 2.7, 3.3, 3.4, or 3.5
  • requests

Upgrading from 2.x.x to 3.x.x

On Python 2.6 or 2.7 with default settings / requests:

No changes are required to upgrade to version 3.

On Python 2.6 or 2.7 with pycurl, httplib, or use_unsafe_ssl = True:

Install requests and test that you are able to connect to the Sandbox environment with version 3 and without specifying an HTTP strategy. The use_unsafe_ssl parameter will be ignored.

On Python 2.5:

Python 2.5 isn't supported by version 3 of the library. Most code that runs on 2.5 will work unmodified on Python 2.6. After making sure your code works on Python 2.6, follow the instructions above for upgrading from pycurl / httplib to requests.


Quick Start Example

import braintree

gateway = braintree.BraintreeGateway(

result ={
    "amount": "1000.00",
    "payment_method_nonce": nonce_from_the_client,
    "options": {
        "submit_for_settlement": True

if result.is_success:
    print("success!: " +
elif result.transaction:
    print("Error processing transaction:")
    print("  code: " + result.transaction.processor_response_code)
    print("  text: " + result.transaction.processor_response_text)
    for error in result.errors.deep_errors:
        print("attribute: " + error.attribute)
        print("  code: " + error.code)
        print("  message: " + error.message)


  1. Create a virtualenv called venv:

    virtualenv venv
  2. Start the virtualenv:

    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

Developing (Docker)

The Makefile and Dockerfile will build an image containing the dependencies and drop you to a terminal where you can run tests.



Our friends at Venmo have an open source library designed to simplify testing of applications using this library.

If you wish to run the tests, make sure you are set up for development (see instructions above). The unit specs can be run by anyone on any system, but the integration specs are meant to be run against a local development server of our gateway code. These integration specs are not meant for public consumption and will likely fail if run on your system. To run unit tests use rake (rake test:unit) or nose (nosetests tests/unit).


See the LICENSE file for more info.