{"id":10318,"library":"types-braintree","title":"Typing Stubs for Braintree","description":"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`.","status":"active","version":"4.42.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","braintree","typeshed","fintech","payments"],"install":[{"cmd":"pip install braintree types-braintree","lang":"bash","label":"Install Braintree SDK and its type stubs"}],"dependencies":[{"reason":"This package provides type stubs for the `braintree` library, which must be installed separately for runtime functionality.","package":"braintree","optional":false}],"imports":[{"note":"Used to set up your Braintree environment (sandbox/production) and credentials. These are runtime imports from the `braintree` library, for which `types-braintree` provides type hints.","symbol":"Configuration","correct":"import braintree; braintree.Configuration(...)"},{"note":"The main entry point for interacting with the Braintree API. These are runtime imports from the `braintree` library, for which `types-braintree` provides type hints.","symbol":"BraintreeGateway","correct":"import braintree; braintree.BraintreeGateway(...)"},{"note":"Enum for specifying the Braintree environment (Sandbox, Production). These are runtime imports from the `braintree` library, for which `types-braintree` provides type hints.","symbol":"Environment","correct":"import braintree; braintree.Environment.Sandbox"}],"quickstart":{"code":"import braintree\nimport os\n\n# Configure Braintree Gateway using environment variables for security\ngateway = braintree.BraintreeGateway(\n    braintree.Configuration(\n        environment=os.environ.get('BRAINTREE_ENVIRONMENT', braintree.Environment.Sandbox),\n        merchant_id=os.environ.get('BRAINTREE_MERCHANT_ID', 'your_sandbox_merchant_id'),\n        public_key=os.environ.get('BRAINTREE_PUBLIC_KEY', 'your_sandbox_public_key'),\n        private_key=os.environ.get('BRAINTREE_PRIVATE_KEY', 'your_sandbox_private_key')\n    )\n)\n\n# Example: Generate a client token (common for web/mobile integrations)\ntry:\n    client_token = gateway.client_token.generate({})\n    print(f\"Generated Client Token: {client_token}\")\nexcept Exception as e:\n    print(f\"Error generating client token: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure both `pip install braintree` and `pip install types-braintree` are run in your environment.","message":"The `types-braintree` package only provides type hints for the `braintree` library. It does not provide any runtime functionality. You must install the `braintree` package itself for your code to run.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Keep both `braintree` and `types-braintree` up to date. If type errors persist for new features, consider contributing to typeshed or temporarily suppressing specific type checker errors.","message":"Mismatching versions between `braintree` and `types-braintree` can lead to incorrect type checking results. Newer features in `braintree` might not yet have stubs, or outdated stubs might conflict with runtime changes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to 3.10 or newer. If you must use an older Python version, you might need to pin `types-braintree` to an older compatible version, which might lack stubs for newer `braintree` features.","message":"Recent versions of `types-braintree` (and `typeshed` generally) require Python 3.10 or newer. Users on older Python versions will encounter installation errors or unexpected type checking behavior.","severity":"breaking","affected_versions":">=4.42.0.x"},{"fix":"Ensure your `BRAINTREE_ENVIRONMENT` and corresponding `merchant_id`, `public_key`, `private_key` environment variables are correctly set for your target environment (Sandbox or Production).","message":"When configuring Braintree, always use `braintree.Environment.Sandbox` for testing and `braintree.Environment.Production` with your actual production keys for live transactions. Using sandbox credentials in production or vice-versa will lead to errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install braintree` to install the core Braintree SDK.","cause":"The actual `braintree` runtime library is not installed in your environment, only the type stubs.","error":"ModuleNotFoundError: No module named 'braintree'"},{"fix":"Ensure `types-braintree` is installed (`pip install types-braintree`) and your type checker is configured to use it. Also, verify both `braintree` and `types-braintree` are up-to-date.","cause":"Your type checker (e.g., mypy, pylance) cannot find the type definition for `Configuration` within the `braintree` module. This usually means `types-braintree` is not installed, not correctly picked up, or is outdated relative to your `braintree` version.","error":"error: Library \"braintree\" has no attribute \"Configuration\" (reportMissingModuleStubs)"},{"fix":"Install `types-braintree` (`pip install types-braintree`) to provide the necessary type definitions for Braintree enums and classes.","cause":"If this error comes from a type checker, it means the type information for `braintree.Environment` is not available. This can happen if `types-braintree` is missing or not properly linked by the type checker.","error":"error: Name \"Environment\" is not defined"}]}