{"id":5003,"library":"paypalhttp","title":"PayPal HTTP Client","description":"paypalhttp is a lightweight, low-level HTTP client library developed by PayPal, designed to wrap API calls to REST APIs. It provides basic HTTP request and response serialization capabilities (JSON, multipart, form-encoded, text). The current stable version is 1.0.1, and it maintains a stable release cadence as a foundational utility for higher-level PayPal SDKs.","status":"active","version":"1.0.1","language":"en","source_language":"en","source_url":"https://github.com/paypal/paypalhttp-python","tags":["paypal","http","client","api","low-level","transport"],"install":[{"cmd":"pip install paypalhttp","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used internally for making HTTP requests.","package":"requests"}],"imports":[{"note":"HttpClient is nested in the 'http_client' module.","wrong":"from paypalhttp import HttpClient","symbol":"HttpClient","correct":"from paypalhttp.http_client import HttpClient"},{"note":"HTTP request classes (GetRequest, PostRequest, etc.) are in the 'requests' module.","wrong":"from paypalhttp.http_client import GetRequest","symbol":"GetRequest","correct":"from paypalhttp.requests import GetRequest"},{"note":"Serializers (JsonSerializer, MultipartSerializer, etc.) are in the 'serializers' module.","wrong":"from paypalhttp.core import JsonSerializer","symbol":"JsonSerializer","correct":"from paypalhttp.serializers import JsonSerializer"}],"quickstart":{"code":"import os\nfrom paypalhttp.http_client import HttpClient\nfrom paypalhttp.requests import GetRequest\nfrom paypalhttp.serializers import JsonSerializer\n\n# Define a custom client that uses a base URL\nclass MyGenericApiClient(HttpClient):\n    def __init__(self):\n        # paypalhttp is a low-level client; it doesn't handle authentication\n        # or full API paths directly. It expects a base URL and relative paths.\n        # In real PayPal SDKs, this would be 'https://api.sandbox.paypal.com'\n        # or 'https://api.paypal.com'. Using httpbin.org for a runnable example.\n        super().__init__('https://httpbin.org')\n\n# Instantiate the custom client\nclient = MyGenericApiClient()\n\n# Create a GET request to a test endpoint\nrequest = GetRequest('/get') # This will hit https://httpbin.org/get\n\n# You can add headers, parameters, or a body (with a serializer)\nrequest.headers['User-Agent'] = 'PayPalHttp-Client-Example'\n\nprint(f\"Making request to: {client.environment_url}{request.path}\")\n\ntry:\n    # Execute the request\n    response = client.execute(request)\n\n    print(f\"\\nStatus Code: {response.status_code}\")\n    print(f\"Headers: {response.headers}\")\n    # The 'result' attribute contains the deserialized response body\n    # For httpbin.org/get, this is typically a JSON object.\n    print(f\"Result (JSON): {response.result}\")\n\nexcept Exception as e:\n    print(f\"\\nError executing request: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to instantiate a basic `HttpClient`, define a GET request, and execute it against a public test API (`httpbin.org`). It highlights the low-level nature of `paypalhttp`, where you define the base URL and manage request details yourself. In a real PayPal integration, `paypalhttp.HttpClient` is typically subclassed to handle authentication and specific PayPal API base URLs."},"warnings":[{"fix":"Use a higher-level PayPal SDK (e.g., `paypal-checkout-serversdk` for checkout or `paypal-payouts-sdk` for payouts) which leverages `paypalhttp` internally and handles API-specific concerns and authentication.","message":"paypalhttp is a low-level HTTP client, not a full PayPal SDK. It provides the HTTP transport layer but does not include high-level API wrappers, specific PayPal API models, or built-in authentication for PayPal's services. Users often expect a higher-level SDK when interacting with 'PayPal' libraries.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When integrating with PayPal APIs, always use `paypalhttp` through a wrapper like `paypalcheckoutsdk.core.PayPalHttpClient` or implement your own `HttpClient` subclass to manage base URLs and inject authentication headers correctly.","message":"Authentication and full API URL construction are external concerns. `paypalhttp.HttpClient` requires a base URL during initialization and expects request objects to provide relative paths. Authentication (e.g., OAuth tokens for PayPal APIs) must be injected into requests or handled by a subclassing client, as shown in official PayPal SDKs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"After executing a request, always check `response.status_code` to determine if the API call was successful (typically `2xx`). Parse `response.result` for API-specific error details when the status code indicates an error.","message":"Error handling for API responses requires explicit checks. While `paypalhttp` will raise exceptions for network or client-side issues, HTTP errors returned by the API (e.g., 400 Bad Request, 404 Not Found, 500 Internal Server Error) are represented in the `response.status_code` and `response.result` attributes, not as exceptions. You must inspect these values.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}