Name | paypal-agent-toolkit JSON |
Version |
1.4.0
JSON |
| download |
home_page | None |
Summary | A toolkit for agent interactions with PayPal API. |
upload_time | 2025-07-25 22:28:00 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | None |
keywords |
paypal
payments
checkout
api
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PayPal Agentic Toolkit
The PayPal Agentic Toolkit integrates PayPal's REST APIs seamlessly with OpenAI, LangChain, CrewAI Agents, allowing AI-driven management of PayPal transactions.
## Available tools
The PayPal Agent toolkit provides the following tools:
**Invoices**
- `create_invoice`: Create a new invoice in the PayPal system
- `list_invoices`: List invoices with optional pagination and filtering
- `get_invoice`: Retrieve details of a specific invoice
- `send_invoice`: Send an invoice to recipients
- `send_invoice_reminder`: Send a reminder for an existing invoice
- `cancel_sent_invoice`: Cancel a sent invoice
- `generate_invoice_qr_code`: Generate a QR code for an invoice
**Payments**
- `create_order`: Create an order in PayPal system based on provided details
- `get_order`: Retrieve the details of an order
- `pay_order`: Process payment for an authorized order
**Dispute Management**
- `list_disputes`: Retrieve a summary of all open disputes
- `get_dispute`: Retrieve detailed information of a specific dispute
- `accept_dispute_claim`: Accept a dispute claim
**Shipment Tracking**
- `create_shipment_tracking`: Create a shipment tracking record
- `get_shipment_tracking`: Retrieve shipment tracking information
**Catalog Management**
- `create_product`: Create a new product in the PayPal catalog
- `list_products`: List products with optional pagination and filtering
- `show_product_details`: Retrieve details of a specific product
**Subscription Management**
- `create_subscription_plan`: Create a new subscription plan
- `list_subscription_plans`: List subscription plans
- `show_subscription_plan_details`: Retrieve details of a specific subscription plan
- `create_subscription`: Create a new subscription
- `show_subscription_details`: Retrieve details of a specific subscription
- `cancel_subscription`: Cancel an active subscription
**Reporting and Insights**
- `list_transactions`: List transactions with optional pagination and filtering
## Prerequisites
Before setting up the workspace, ensure you have the following installed:
- Python 3.11 or higher
- `pip` (Python package manager)
- A PayPal developer account for API credentials
## Installation
You don't need this source code unless you want to modify the package. If you just
want to use the package, just run:
```sh
pip install paypal-agent-toolkit
```
## Configuration
To get started, configure the toolkit with your PayPal API credentials from the [PayPal Developer Dashboard][app-keys].
```python
from paypal_agent_toolkit.shared.configuration import Configuration, Context
configuration = Configuration(
actions={
"orders": {
"create": True,
"get": True,
"capture": True,
}
},
context=Context(
sandbox=True
)
)
```
### Logging Information
The toolkit uses Python’s standard logging module to output logs. By default, logs are sent to the console. It is recommended to configure logging to a file to capture any errors or debugging information for easier troubleshooting.
Recommendations:
- Error Logging: Set the logging output to a file to ensure all errors are recorded.
- Debugging Payloads/Headers: To see detailed request payloads and headers, set the logging level to DEBUG.
```python
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)
```
## Usage Examples
This toolkit is designed to work with OpenAI's Agent SDK and Assistant API, langchain, crewai. It provides pre-built tools for managing PayPal transactions like creating, capturing, and checking orders details etc.
### OpenAI Agent
```python
from agents import Agent, Runner
from paypal_agent_toolkit.openai.toolkit import PayPalToolkit
# Initialize toolkit
toolkit = PayPalToolkit(PAYPAL_CLIENT_ID, PAYPAL_SECRET, configuration)
tools = toolkit.get_tools()
# Initialize OpenAI Agent
agent = Agent(
name="PayPal Assistant",
instructions="""
You're a helpful assistant specialized in managing PayPal transactions:
- To create orders, invoke create_order.
- After approval by user, invoke pay_order.
- To check an order status, invoke get_order_status.
""",
tools=tools
)
# Initialize the runner to execute agent tasks
runner = Runner()
user_input = "Create an PayPal Order for $10 for AdsService"
# Run the agent with user input
result = await runner.run(agent, user_input)
```
### OpenAI Assistants API
```python
from openai import OpenAI
from paypal_agent_toolkit.openai.toolkit import PayPalToolkit
# Initialize toolkit
toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)
tools = toolkit.get_openai_chat_tools()
paypal_api = toolkit.get_paypal_api()
# OpenAI client
client = OpenAI()
# Create assistant
assistant = client.beta.assistants.create(
name="PayPal Checkout Assistant",
instructions=f"""
You help users create and process payment for PayPal Orders. When the user wants to make a purchase,
use the create_order tool and share the approval link. After approval, use pay_order.
""",
model="gpt-4-1106-preview",
tools=tools
)
# Create a new thread for conversation
thread = client.beta.threads.create()
# Execute the assistant within the thread
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
```
### LangChain Agent
```python
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from paypal_agent_toolkit.langchain.toolkit import PayPalToolkit
# Initialize Langchain Toolkit
toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)
tools = toolkit.get_tools()
# Setup LangChain Agent
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
prompt = "Create an PayPal order for $50 for Premium News service."
# Run the agent with the defined prompt
result = agent.run(prompt)
```
### CrewAI Agent
```python
from crewai import Agent, Crew, Task
from paypal_agent_toolkit.crewai.toolkit import PayPalToolkit
# Setup PayPal CrewAI Toolkit
toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)
tools = toolkit.get_tools()
# Define an agent specialized in PayPal transactions
agent = Agent(
role="PayPal Assistant",
goal="Help users create and manage PayPal transactions",
backstory="You are a finance assistant skilled in PayPal operations.",
tools=toolkit.get_tools(),
allow_delegation=False
)
# Define a CrewAI Task to create a PayPal order
task = Task(
description="Create an PayPal order for $50 for Premium News service.",
expected_output="A PayPal order ID",
agent=agent
)
# Assemble Crew with defined agent and task
crew = Crew(agents=[agent], tasks=[task], verbose=True,
planning=True,)
```
### Amazon Bedrock
```python
import boto3
from botocore.exceptions import ClientError
from paypal_agent_toolkit.bedrock.toolkit import PayPalToolkit, BedrockToolBlock
from paypal_agent_toolkit.shared.configuration import Configuration, Context
# Setup PayPal Amazon Bedrock toolkit
toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_CLIENT_SECRET, configuration = configuration)
tools = toolkit.get_tools()
# Create a user message
userMessage = "Create one PayPal order for $50 for Premium News service with 10% tax."
messages = [
{
"role": "user",
"content": [{ "text": userMessage }],
}
]
# Handles the appropriate tool calls
async def main():
try:
while True:
response = client.converse(
modelId=model_id,
messages=messages,
toolConfig={
"tools": tools
}
)
response_message = response["output"]["message"]
if not response_message:
print("No response message received.")
break
response_content = response["output"]["message"]["content"]
tool_call = [content for content in response_content if content.get("toolUse")]
if not tool_call:
print(response_content[0]["text"])
break
messages.append(response_message)
for tool in tool_call:
try:
tool_call = BedrockToolBlock(
toolUseId=tool["toolUse"]["toolUseId"],
name=tool["toolUse"]["name"],
input=tool["toolUse"]["input"]
)
result = await toolkit.handle_tool_call(tool_call)
print(result.content)
messages.append({
"role": "user",
"content": [{
"toolResult": {
"toolUseId": result.toolUseId,
"content": result.content,
}
}]
})
except:
print(f"ERROR: Can't invoke tool '{tool['toolUse']['name']}'.")
break
except (ClientError, Exception) as e:
print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
exit(1)
```
## Examples
See /examples for ready-to-run samples using:
- [OpenAI Agent SDK](https://github.com/paypal/agent-toolkit/tree/main/python/examples/openai/app_agent.py)
- [Assistants API](https://github.com/paypal/agent-toolkit/tree/main/python/examples/openai/app_assistant_chatbot.py)
- [LangChain integration](https://github.com/paypal/agent-toolkit/tree/main/python/examples/langchain/app_agent.py)
- [CrewAI integration](https://github.com/paypal/agent-toolkit/tree/main/python/examples/crewai/app_agent.py)
## Disclaimer
AI-generated content may be inaccurate or incomplete. Users are responsible for independently verifying any information before relying on it. PayPal makes no guarantees regarding output accuracy and is not liable for any decisions, actions, or consequences resulting from its use.
[app-keys]: https://developer.paypal.com/dashboard/applications/sandbox
Raw data
{
"_id": null,
"home_page": null,
"name": "paypal-agent-toolkit",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "paypal, payments, checkout, api",
"author": null,
"author_email": "PayPal <support@paypal.com>",
"download_url": "https://files.pythonhosted.org/packages/20/c1/f7fe86c226c4543dfc02279de0a19ba3e95d44749a7487c88bdac8c2015e/paypal_agent_toolkit-1.4.0.tar.gz",
"platform": null,
"description": "# PayPal Agentic Toolkit\n\nThe PayPal Agentic Toolkit integrates PayPal's REST APIs seamlessly with OpenAI, LangChain, CrewAI Agents, allowing AI-driven management of PayPal transactions.\n\n## Available tools\n\nThe PayPal Agent toolkit provides the following tools:\n\n**Invoices**\n\n- `create_invoice`: Create a new invoice in the PayPal system\n- `list_invoices`: List invoices with optional pagination and filtering\n- `get_invoice`: Retrieve details of a specific invoice\n- `send_invoice`: Send an invoice to recipients\n- `send_invoice_reminder`: Send a reminder for an existing invoice\n- `cancel_sent_invoice`: Cancel a sent invoice\n- `generate_invoice_qr_code`: Generate a QR code for an invoice\n\n**Payments**\n\n- `create_order`: Create an order in PayPal system based on provided details\n- `get_order`: Retrieve the details of an order\n- `pay_order`: Process payment for an authorized order\n\n**Dispute Management**\n\n- `list_disputes`: Retrieve a summary of all open disputes\n- `get_dispute`: Retrieve detailed information of a specific dispute\n- `accept_dispute_claim`: Accept a dispute claim\n\n**Shipment Tracking**\n\n- `create_shipment_tracking`: Create a shipment tracking record\n- `get_shipment_tracking`: Retrieve shipment tracking information\n\n**Catalog Management**\n\n- `create_product`: Create a new product in the PayPal catalog\n- `list_products`: List products with optional pagination and filtering\n- `show_product_details`: Retrieve details of a specific product\n\n**Subscription Management**\n\n- `create_subscription_plan`: Create a new subscription plan\n- `list_subscription_plans`: List subscription plans\n- `show_subscription_plan_details`: Retrieve details of a specific subscription plan\n- `create_subscription`: Create a new subscription\n- `show_subscription_details`: Retrieve details of a specific subscription\n- `cancel_subscription`: Cancel an active subscription\n\n**Reporting and Insights**\n\n- `list_transactions`: List transactions with optional pagination and filtering\n\n\n## Prerequisites\n\nBefore setting up the workspace, ensure you have the following installed:\n- Python 3.11 or higher\n- `pip` (Python package manager)\n- A PayPal developer account for API credentials\n\n## Installation\n\nYou don't need this source code unless you want to modify the package. If you just\nwant to use the package, just run:\n\n```sh\npip install paypal-agent-toolkit\n```\n\n## Configuration\n\nTo get started, configure the toolkit with your PayPal API credentials from the [PayPal Developer Dashboard][app-keys].\n\n```python\nfrom paypal_agent_toolkit.shared.configuration import Configuration, Context\n\nconfiguration = Configuration(\n actions={\n \"orders\": {\n \"create\": True,\n \"get\": True,\n \"capture\": True,\n }\n },\n context=Context(\n sandbox=True\n )\n)\n\n```\n\n### Logging Information\nThe toolkit uses Python\u2019s standard logging module to output logs. By default, logs are sent to the console. It is recommended to configure logging to a file to capture any errors or debugging information for easier troubleshooting.\n\nRecommendations:\n- Error Logging: Set the logging output to a file to ensure all errors are recorded.\n- Debugging Payloads/Headers: To see detailed request payloads and headers, set the logging level to DEBUG.\n\n```python\nimport logging\n\n# Basic configuration: logs to a file with INFO level\nlogging.basicConfig(\n filename='paypal_agent_toolkit.log', \n level=logging.INFO,\n format='%(asctime)s %(levelname)s %(name)s %(message)s'\n)\n\n# To enable debug-level logs (for seeing payloads and headers)\n# logging.getLogger().setLevel(logging.DEBUG)\n\n```\n\n\n## Usage Examples\n\nThis toolkit is designed to work with OpenAI's Agent SDK and Assistant API, langchain, crewai. It provides pre-built tools for managing PayPal transactions like creating, capturing, and checking orders details etc.\n\n### OpenAI Agent\n```python\nfrom agents import Agent, Runner\nfrom paypal_agent_toolkit.openai.toolkit import PayPalToolkit\n\n# Initialize toolkit\ntoolkit = PayPalToolkit(PAYPAL_CLIENT_ID, PAYPAL_SECRET, configuration)\ntools = toolkit.get_tools()\n\n# Initialize OpenAI Agent\nagent = Agent(\n name=\"PayPal Assistant\",\n instructions=\"\"\"\n You're a helpful assistant specialized in managing PayPal transactions:\n - To create orders, invoke create_order.\n - After approval by user, invoke pay_order.\n - To check an order status, invoke get_order_status.\n \"\"\",\n tools=tools\n)\n# Initialize the runner to execute agent tasks\nrunner = Runner()\n\nuser_input = \"Create an PayPal Order for $10 for AdsService\"\n# Run the agent with user input\nresult = await runner.run(agent, user_input)\n```\n\n\n### OpenAI Assistants API\n```python\nfrom openai import OpenAI\nfrom paypal_agent_toolkit.openai.toolkit import PayPalToolkit\n\n# Initialize toolkit\ntoolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)\ntools = toolkit.get_openai_chat_tools()\npaypal_api = toolkit.get_paypal_api()\n\n# OpenAI client\nclient = OpenAI()\n\n# Create assistant\nassistant = client.beta.assistants.create(\n name=\"PayPal Checkout Assistant\",\n instructions=f\"\"\"\nYou help users create and process payment for PayPal Orders. When the user wants to make a purchase,\nuse the create_order tool and share the approval link. After approval, use pay_order.\n\"\"\",\n model=\"gpt-4-1106-preview\",\n tools=tools\n)\n\n# Create a new thread for conversation\nthread = client.beta.threads.create()\n\n# Execute the assistant within the thread\nrun = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)\n```\n\n### LangChain Agent\n```python\nfrom langchain.agents import initialize_agent, AgentType\nfrom langchain_openai import ChatOpenAI \nfrom paypal_agent_toolkit.langchain.toolkit import PayPalToolkit\n\n# Initialize Langchain Toolkit\ntoolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)\ntools = toolkit.get_tools()\n\n# Setup LangChain Agent\nagent = initialize_agent(\n tools=tools,\n llm=llm,\n agent=AgentType.OPENAI_FUNCTIONS,\n verbose=True\n)\n\nprompt = \"Create an PayPal order for $50 for Premium News service.\"\n# Run the agent with the defined prompt\nresult = agent.run(prompt)\n```\n\n### CrewAI Agent\n```python\nfrom crewai import Agent, Crew, Task\nfrom paypal_agent_toolkit.crewai.toolkit import PayPalToolkit\n\n# Setup PayPal CrewAI Toolkit\ntoolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)\ntools = toolkit.get_tools()\n\n# Define an agent specialized in PayPal transactions\nagent = Agent(\n role=\"PayPal Assistant\",\n goal=\"Help users create and manage PayPal transactions\",\n backstory=\"You are a finance assistant skilled in PayPal operations.\",\n tools=toolkit.get_tools(),\n allow_delegation=False\n)\n\n# Define a CrewAI Task to create a PayPal order\ntask = Task(\n description=\"Create an PayPal order for $50 for Premium News service.\",\n expected_output=\"A PayPal order ID\",\n agent=agent\n)\n\n# Assemble Crew with defined agent and task\ncrew = Crew(agents=[agent], tasks=[task], verbose=True,\n planning=True,)\n\n```\n\n### Amazon Bedrock\n```python\nimport boto3\nfrom botocore.exceptions import ClientError\nfrom paypal_agent_toolkit.bedrock.toolkit import PayPalToolkit, BedrockToolBlock\nfrom paypal_agent_toolkit.shared.configuration import Configuration, Context\n\n# Setup PayPal Amazon Bedrock toolkit\ntoolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_CLIENT_SECRET, configuration = configuration)\ntools = toolkit.get_tools()\n\n# Create a user message\nuserMessage = \"Create one PayPal order for $50 for Premium News service with 10% tax.\"\nmessages = [\n {\n \"role\": \"user\",\n \"content\": [{ \"text\": userMessage }],\n }\n]\n\n# Handles the appropriate tool calls\nasync def main():\n try: \n while True: \n response = client.converse(\n modelId=model_id,\n messages=messages,\n toolConfig={\n \"tools\": tools\n }\n )\n\n response_message = response[\"output\"][\"message\"]\n if not response_message:\n print(\"No response message received.\")\n break\n\n response_content = response[\"output\"][\"message\"][\"content\"]\n tool_call = [content for content in response_content if content.get(\"toolUse\")]\n if not tool_call:\n print(response_content[0][\"text\"])\n break\n\n messages.append(response_message)\n for tool in tool_call:\n try: \n tool_call = BedrockToolBlock(\n toolUseId=tool[\"toolUse\"][\"toolUseId\"],\n name=tool[\"toolUse\"][\"name\"],\n input=tool[\"toolUse\"][\"input\"]\n )\n result = await toolkit.handle_tool_call(tool_call)\n print(result.content)\n messages.append({\n \"role\": \"user\",\n \"content\": [{\n \"toolResult\": {\n \"toolUseId\": result.toolUseId,\n \"content\": result.content,\n }\n }]\n })\n except:\n print(f\"ERROR: Can't invoke tool '{tool['toolUse']['name']}'.\")\n break\n\n except (ClientError, Exception) as e:\n print(f\"ERROR: Can't invoke '{model_id}'. Reason: {e}\")\n exit(1)\n```\n\n\n## Examples\nSee /examples for ready-to-run samples using:\n\n - [OpenAI Agent SDK](https://github.com/paypal/agent-toolkit/tree/main/python/examples/openai/app_agent.py)\n - [Assistants API](https://github.com/paypal/agent-toolkit/tree/main/python/examples/openai/app_assistant_chatbot.py)\n - [LangChain integration](https://github.com/paypal/agent-toolkit/tree/main/python/examples/langchain/app_agent.py)\n - [CrewAI integration](https://github.com/paypal/agent-toolkit/tree/main/python/examples/crewai/app_agent.py)\n\n\n## Disclaimer\nAI-generated content may be inaccurate or incomplete. Users are responsible for independently verifying any information before relying on it. PayPal makes no guarantees regarding output accuracy and is not liable for any decisions, actions, or consequences resulting from its use.\n\n[app-keys]: https://developer.paypal.com/dashboard/applications/sandbox\n",
"bugtrack_url": null,
"license": null,
"summary": "A toolkit for agent interactions with PayPal API.",
"version": "1.4.0",
"project_urls": {
"Bug Tracker": "https://github.com/paypal/agent-toolkit/issues",
"Source Code": "https://github.com/paypal/agent-toolkit"
},
"split_keywords": [
"paypal",
" payments",
" checkout",
" api"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "20af67b81433d68261162d4bbec30821f8fb4956b76f8b148082f7f9cd3dbb8f",
"md5": "0d47ff207fc501d7e1a2b8a8bdb3eaf1",
"sha256": "5cd4a0bee685929bb782f1eaa6db1389c9453792b0b412b030a4eec5975cd966"
},
"downloads": -1,
"filename": "paypal_agent_toolkit-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0d47ff207fc501d7e1a2b8a8bdb3eaf1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 34781,
"upload_time": "2025-07-25T22:27:58",
"upload_time_iso_8601": "2025-07-25T22:27:58.677993Z",
"url": "https://files.pythonhosted.org/packages/20/af/67b81433d68261162d4bbec30821f8fb4956b76f8b148082f7f9cd3dbb8f/paypal_agent_toolkit-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "20c1f7fe86c226c4543dfc02279de0a19ba3e95d44749a7487c88bdac8c2015e",
"md5": "7d8f20a327b3b3207789f730df86b132",
"sha256": "0731a0e356ae13e18d3e74523777a6e0b5a48f975ea5d64bced09a39d8317986"
},
"downloads": -1,
"filename": "paypal_agent_toolkit-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "7d8f20a327b3b3207789f730df86b132",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 27016,
"upload_time": "2025-07-25T22:28:00",
"upload_time_iso_8601": "2025-07-25T22:28:00.070188Z",
"url": "https://files.pythonhosted.org/packages/20/c1/f7fe86c226c4543dfc02279de0a19ba3e95d44749a7487c88bdac8c2015e/paypal_agent_toolkit-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-25 22:28:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "paypal",
"github_project": "agent-toolkit",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "paypal-agent-toolkit"
}