Paypal Python 3 API integration
Project description
PYTHON-PAYPAL-API
Paypal's Rest API
A python 3 wrapper to access Paypal Rest API with an easy-to-use interface.
Install
pip install python-paypal-api
Donate
If you find this project is useful consider donating or sponsor it to keep on going on it, thank you.
Overview
You need obtain your own credentials with Paypal that may include a paypal personal or business account and access as developer. Please view the official Paypal Developer
Environment Credentials
from python_paypal_api.api import Identity
os.environ["client_id"] = "your-client-id"
os.environ["client_secret"] = "your-client-secret"
# os.environ["client_mode"] = "PRODUCTION"
# Can omit client_mode if using SANDBOX
result = Identity().get_userinfo()
Code Credentials
You can use your credentials as follows passing it to the client as a dict. Please review the full documentation to see all posibilities to include your credentials.
Python code
from python_paypal_api.api import Identity
my_credentials = dict(
client_id="your-client-id",
client_secret="your-client-secret",
client_mode="PRODUCTION"
)
# Can omit client_mode to use SANDBOX
result = Identity(credentials=my_credentials).get_userinfo()
YAML Credentials
Use a credentials.yml file with your credentials for more convenience and manage diferent accounts or profiles. You can store a Sandbox and Production (Live) credentials to comvenient switch from sandbox to live environment. Note: default credentials without client_mode will use SANDBOX paypal endpoint for testing
Create a file credentials.yml
version: '1.0'
default:
client_id: 'your-client-id-sandbox'
client_secret: 'your-client-secret-sandbox'
production:
client_id: 'your-client-id'
client_secret: 'your-client-secret'
client_mode: 'PRODUCTION'
Python code
from python_paypal_api.api import Identity
# Leave empty will use the 'default' account
result = Identity().get_userinfo()
# will use germany account data
result = Identity(credentials="production").get_userinfo()
Search path for credentials.yml
- macOS and Other Unix:
~/.config/python-paypal-api
- Windows:
%APPDATA%\python-paypal-api
where the APPDATA environment variable falls back to%HOME%\AppData\Roaming
if undefined
Exceptions
You can use a try except statement when you call the API and catch exceptions if some problem ocurred:
from python_paypal_api.api import Identity, Catalog
from python_paypal_api.base import PaypalApiException
import logging
try:
result = Identity().get_userinfo()
logging.info(result)
except PaypalApiException as error:
logging.error(error)
Debug
Use debug=True if you want see some logs like the header you submit to the api endpoint, the method and path used among the params and the data submitted if any, to trace possible errors.
from python_paypal_api.api import Identity, Catalog
from python_paypal_api.base import PaypalApiException
import logging
try:
result = Identity(debug=True).get_userinfo()
logging.info(result)
except PaypalApiException as error:
logging.error(error)
Paypal Current Resources
- Catalog
- Disputes
- Identity
- Invoices
- Orders
- Partner Referral
- Tracking
- Transactions
API NOTICE
This API is based on the API Client created by @saleweaver but adapted to paypal auth requeriments and improved system for token call
DISCLAIMER
We are not affiliated with PayPal
LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-paypal-api-0.0.5.tar.gz
.
File metadata
- Download URL: python-paypal-api-0.0.5.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d485fa262b15cb8429be288b0c2dbe8aee038038194538e69b0dae5f35a3d1 |
|
MD5 | 5e8eda744f978a089cb779699fe4ce60 |
|
BLAKE2b-256 | 017a19037470b417f067193107cb2831cebe41a738d57ce42ef95257842841bd |
File details
Details for the file python_paypal_api-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: python_paypal_api-0.0.5-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47efaae7a1e69940ed57a297ef3e733780ae1202c90509c54f5207b4bc605264 |
|
MD5 | 9ed4168cbcc1ae8286089eba19751f55 |
|
BLAKE2b-256 | f549dca656b3428554fb8ef2739a1e73e7fccd9878189206f8143ac38f3ea56a |