Skip to main content

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

You can also check how use the credentials on the documentation of this Python Paypal API.

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 config.yaml 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 config.yaml (From version 0.1.1 the file use the default name provided by confuse package and use template validation)

Please review the full documentation to see all posibilities to include in your configuration.

version: '1.0'

configuration:

  production:
    client_id: 'your-client-id'
    client_secret: 'your-client-secret'
    client_mode: 'PRODUCTION'
  default:
    client_id: 'your-client-id-sandbox'
    client_secret: 'your-client-secret-sandbox'

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 config.yaml

  • macOS: ~/.config/python-paypal-api and ~/Library/Application Support/python-paypal-api
  • Other Unix: ~/.config/python-paypal-api and /etc/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 store it in cache 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.

There is a way to 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. The token also can be stored encrypted, for complex configurations read the Python Paypal API Help.

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

try:

    result = Identity(store_credentials=True).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
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,
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

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

Metadata

Release files for python-paypal-api 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-paypal-api 0.1.2
File Size Uploaded
python-paypal-api-0.1.2.tar.gz 43.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-paypal-api 0.1.2
File Interpreter ABI Platform
python_paypal_api-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 91.3 kB

Release files / python-paypal-api-0.1.2.tar.gz

Download URL python-paypal-api-0.1.2.tar.gz
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cd26decd82a8317fc4554ae2176dc7f0e7937d3425cdf03eff22b4d1299674ec
BLAKE2b-256 checksum
How to use checksums
c1cd961a3da8cfe15ce51a6b008bb365f298c3b947652221976dfd129f27a7f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / python_paypal_api-0.1.2-py3-none-any.whl

Download URL python_paypal_api-0.1.2-py3-none-any.whl
Size 47.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
468bec1e86e6458d3dc95221e2d20356c4d932a835fc4fcaeef51c830a2a7873
BLAKE2b-256 checksum
How to use checksums
cb76dadc6ca7ed56f93db3b89830690b3cb5325f5967d207d6a9a97d2a746c21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page