Skip to main content

Paypal Python 3 API integration

Project description

PYTHON-PAYPAL-API

CodeQL Documentation Status

Paypal's Rest API

A python 3 wrapper to access Paypal Rest API with an easy-to-use interface.

Install

Badge

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.

paypal

alt text

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

Confuse Help

Managing obtained credentials

By default the package will create a 600 permissions file in the configuration search path. This is because the token obtained it will ve valid for 32400 seconds and storing it will reduce the calls to the oauth paypal endpoint. If you don't want to store it in a file there is an option to use the LRU Cache from cachetools but the cache will be available only during the script living environment, so once you get the token, any call will use the cached token but since the script terminates the cached key will be gone.

from python_paypal_api.api import Identity, Catalog
from python_paypal_api.base import PaypalApiException
import logging

try:
  result = Identity(store_credentials=False).get_userinfo()
    logging.info(result)

except PaypalApiException as error:
    logging.error(error)

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

License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-paypal-api-0.0.9.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

python_paypal_api-0.0.9-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file python-paypal-api-0.0.9.tar.gz.

File metadata

  • Download URL: python-paypal-api-0.0.9.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for python-paypal-api-0.0.9.tar.gz
Algorithm Hash digest
SHA256 e28a8c6db8ede7a3de23d73d6b6d5df0e1250fc3d368e0a3cccae5fcd5906936
MD5 3ba6c7264a62209fc686b25c5b2b535d
BLAKE2b-256 65fc17a0a1ab8d06d5d3c69597f3037b95bc1efbc69db228a3841a162ff94d88

See more details on using hashes here.

File details

Details for the file python_paypal_api-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for python_paypal_api-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 28fcd5f1e9fbcb5183e0896711879afb41b40a4f9bbbe3a9b14d2b6fd5cbffce
MD5 fa82f282f73da05c58d678abd25d2a64
BLAKE2b-256 d94d767cb7d1724650e08cd140be7cb69fe853204c94032c417938a1b137a911

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page