Install the PayPal Agentic Toolkit via pip
mainTo use the PayPal Agentic Toolkit in your Python project, install it using pip. Ensure you have Python 3.11 or higher installed.
pip install paypal-agent-toolkitrepository·main·Indexed 41 days ago
https://github.com/paypal/agent-toolkitA toolkit for agent interactions with PayPal API version 1.11.0. It enables agent frameworks including OpenAI Agent SDK, LangChain, Vercel AI SDK, CrewAI, Amazon Bedrock, and MCP to interact with PayPal APIs through function calling. The toolkit provides pre-built tools for managing invoices, payments, disputes, subscriptions, shipment tracking, catalog management, and reporting.
To use the PayPal Agentic Toolkit in your Python project, install it using pip. Ensure you have Python 3.11 or higher installed.
pip install paypal-agent-toolkitTo run the OpenAI example, you must configure your environment with both OpenAI and PayPal credentials. You can populate these variables in your local shell environment or in a .env file at the root of the project.
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
PAYPAL_CLIENT_ID=PayPal_Client_ID
PAYPAL_CLIENT_SECRET=PayPal_Client_SecretThe toolkit uses Python's standard logging module. It is recommended to log to a file. To inspect detailed request payloads and headers for debugging, set the logging level to DEBUG.
import logging
# Basic configuration: logs to a file with INFO level
logging.basicConfig(
filename='paypal_agent_toolkit.log',
level=logging.INFO,
format='%(asctime)s %(levelname)s %(name)s %(message)s'
)
# To enable debug-level logs (for seeing payloads and headers)
# logging.getLogger().setLevel(logging.DEBUG)To set up the Python example workspace, create a virtual environment, activate it, and install the necessary dependencies using pip.
python -m venv venvsource venv/bin/activatevenv\Scripts\activatepip install -r requirements.txt# Step 1: Create a virtual environment
python -m venv venv
# Step 2: Activate the virtual environment
source venv/bin/activate # On macOS/Linux
# For Windows:
# venv\Scripts\activate
# Step 3: Install required dependencies
pip install -r requirements.txtTo run the LangChain example, you must configure the following environment variables in your local environment or in a .env file. You will need an OpenAI API key and your PayPal credentials (Client ID and Client Secret) to authenticate with PayPal services.
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
PAYPAL_CLIENT_ID=PayPal_Client_ID
PAYPAL_CLIENT_SECRET=PayPal_Client_SecretTo integrate with PayPal APIs, you need an access token. You can generate one using cURL by providing your Client ID and Client Secret.
For Sandbox: Use https://api-m.sandbox.paypal.com/v1/oauth2/token.
For Production: Use https://api-m.paypal.com/v1/oauth2/token.
curl -v https://api-m.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "CLIENT_ID:CLIENT_SECRET" \
-d "grant_type=client_credentials"To use the toolkit in a TypeScript project, install the package via npm. Ensure you are using Node.js version 18 or higher.
npm install @paypal/agent-toolkitOnce the environment is configured and dependencies are installed, you can launch the assistant application by running the app.py script.
python app.pyTo run the Bedrock example, you must configure your local environment or a .env file with the following credentials for AWS and PayPal:
AWS_ACCESS_KEY_ID: Your AWS access key.AWS_SECRET_ACCESS_KEY: Your AWS secret access key.PAYPAL_CLIENT_ID: Your PayPal Client ID.PAYPAL_CLIENT_SECRET: Your PayPal Client Secret.AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
PAYPAL_CLIENT_ID=PayPal_Client_ID
PAYPAL_CLIENT_SECRET=PayPal_Client_SecretTo run the AI SDK example, you must configure your environment with the necessary API keys and PayPal credentials. You can either export these as local environment variables or include them in a .env file in your project root.
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
PAYPAL_CLIENT_ID=PayPal_Client_ID
PAYPAL_CLIENT_SECRET=PayPal_Client_SecretThe examples require an .env file in the example directory containing credentials for OpenAI, Amazon Bedrock, and PayPal. Replace the placeholders with your actual service credentials.
Required keys:
OPENAI_API_KEY: Your OpenAI API key.AWS_ACCESS_KEY_ID: Your AWS access key ID for Bedrock.AWS_SECRET_ACCESS_KEY: Your AWS secret access key for Bedrock.PAYPAL_CLIENT_ID: Your PayPal developer client ID.PAYPAL_SECRET: Your PayPal developer secret.# OpenAI Configuration
OPENAI_API_KEY=<your_openai_api_key>
# Amazon Bedrock Configuration
AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
# PayPal Configuration
PAYPAL_CLIENT_ID=<your_paypal_client_id>
PAYPAL_SECRET=<your_paypal_secret>The toolkit provides a suite of functions to manage the lifecycle of PayPal invoices. You can create new invoices, retrieve existing ones, list multiple invoices, and send them to recipients. It also supports advanced features like setting up automatic reminders, generating QR codes for payments, and recording payments or refunds against specific invoices.
Key capabilities include:
createInvoice, getInvoice, listInvoices.sendInvoice, sendInvoiceReminder, setupInvoiceAutoReminder, cancelInvoiceAutoReminder.cancelSentInvoice, deleteInvoice, generateInvoiceNumber.recordPaymentForInvoice, recordRefundForInvoice, createConditionalRulesForInvoice.generateInvoiceQrCode.