Registry / http-networking / paypalhttp

paypalhttp

JSON →
library1.0.1pypypi✓ verified 21d ago

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.

pip install paypalhttp
INSTALL
IMPORT
SIG · PAYPALHTTP
P
paypalhttp
http-networkingpythonv1.0.1
Install
3.1s avg
Import
379ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.386s · 38.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.372s · 39MB
37MB installed
● package 37MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpClient
from paypalhttp.http_client import HttpClient
from paypalhttp import HttpClient
HttpClient is nested in the 'http_client' module.
GetRequest
from paypalhttp.requests import GetRequest
from paypalhttp.http_client import GetRequest
HTTP request classes (GetRequest, PostRequest, etc.) are in the 'requests' module.
JsonSerializer
from paypalhttp.serializers import JsonSerializer
from paypalhttp.core import JsonSerializer
Serializers (JsonSerializer, MultipartSerializer, etc.) are in the 'serializers' module.

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.

import os from paypalhttp.http_client import HttpClient from paypalhttp.requests import GetRequest from paypalhttp.serializers import JsonSerializer # Define a custom client that uses a base URL class MyGenericApiClient(HttpClient): def __init__(self): # paypalhttp is a low-level client; it doesn't handle authentication # or full API paths directly. It expects a base URL and relative paths. # In real PayPal SDKs, this would be 'https://api.sandbox.paypal.com' # or 'https://api.paypal.com'. Using httpbin.org for a runnable example. super().__init__('https://httpbin.org') # Instantiate the custom client client = MyGenericApiClient() # Create a GET request to a test endpoint request = GetRequest('/get') # This will hit https://httpbin.org/get # You can add headers, parameters, or a body (with a serializer) request.headers['User-Agent'] = 'PayPalHttp-Client-Example' print(f"Making request to: {client.environment_url}{request.path}") try: # Execute the request response = client.execute(request) print(f"\nStatus Code: {response.status_code}") print(f"Headers: {response.headers}") # The 'result' attribute contains the deserialized response body # For httpbin.org/get, this is typically a JSON object. print(f"Result (JSON): {response.result}") except Exception as e: print(f"\nError executing request: {e}")
Debug
Known issues
gotchapaypalhttp 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.
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.
affects: All versions
gotchaAuthentication 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.
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.
affects: All versions
gotchaError 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.
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.
affects: All versions
Errors
Common errors & fixes
paypalhttp.HttpException: {'name': 'INVALID_REQUEST', 'message': 'The request is not well-formed, syntactically incorrect, or violates schema.'}
This error occurs when the data sent in your API request, such as JSON body, query parameters, or headers, is malformed, missing required fields, or has incorrect data types, preventing the PayPal API from processing it.
fix
Thoroughly review the PayPal API documentation for the specific endpoint you are calling to ensure your request body's structure, required fields, and data types (e.g., string vs. number, correct currency codes, maximum lengths) precisely match the API's expectations. Use a JSON validator to check for syntax errors.
paypalhttp.HttpException: {'name': 'AUTHENTICATION_FAILURE', 'message': 'Authentication failed due to missing Authorization header, or invalid authentication credentials.'}
This error indicates that the provided API credentials (Client ID and Secret) are incorrect, expired, or are being used in the wrong environment (e.g., sandbox credentials used in live mode or vice-versa), or that the necessary authorization header is missing.
fix
Verify that your Client ID and Secret are correct and match the target environment (sandbox or live). Ensure they are properly base64-encoded and included in the 'Authorization' header as a Bearer token when obtaining an access token, and that the access token is correctly used for subsequent requests.
AttributeError: 'HttpResponse' object has no attribute 'get'
This error arises when you incorrectly try to access data from a `paypalhttp.HttpResponse` object using dictionary-like `get()` method, while the result data is typically stored in the `result` attribute of the `HttpResponse` object.
fix
Access the deserialized response data via the `response.result` attribute. If the `response.result` itself is a dictionary-like object, then you can use `.get()` on it. For example: `data = response.result.get('some_key')` or `print(response.result)` to inspect its structure.
ModuleNotFoundError: No module named 'paypalhttp'
This error occurs when the `paypalhttp` library has not been installed in your Python environment or is not accessible within your project's `PYTHONPATH`.
fix
Install the `paypalhttp` library using pip: `pip install paypalhttp`. If you are using a virtual environment, ensure it is activated before installation. If the issue persists, check your Python environment and `PYTHONPATH` settings.
Upgrade
Version history
1.0.1latest on PyPI · released Sep 14, 2021
Audit
Dependencies
requestsrequiredUsed internally for making HTTP requests.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
paypalhttp — pip install paypalhttp · libregistry