Skip to main content

Payload Python Library

A Python library for integrating Payload.

Installation

Install using pip

pip install payload-api

Get Started

Once you've installed the Payload Python library to your environment, import the payload module to get started. Note: We recommend using the shorthand name of pl when importing.

import payload as pl

API Authentication

To authenticate with the Payload API, you'll need a live or test API key. API keys are accessible from within the Payload dashboard.

import payload as pl
pl.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE'

Session based:

import payload
pl = payload.Session('secret_key_3bW9JMZtPVDOfFNzwRdfE')

API Versioning

The Payload API supports multiple versions. You can specify which version to use when making requests:

import payload as pl
pl.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE'
pl.api_version = 'v2'  # Use API v2

Or with sessions:

import payload
pl = payload.Session(
    'secret_key_3bW9JMZtPVDOfFNzwRdfE',
    api_version='v2'
)

API v2 introduces new objects including Profile, Intent, Entity, Transfer, ProcessingAgreement, and more. See the Payload API Documentation for details on API versions.

Creating an Object

Interfacing with the Payload API is done primarily through Payload Objects. Below is an example of creating a customer using the pl.Customer object.

# Create a Customer
customer = pl.Customer.create(
	email='matt.perez@example.com',
	name='Matt Perez'
)
# Create a Payment
payment = pl.Payment.create(
    amount=100.0,
    payment_method=pl.Card(
        card_number='4242 4242 4242 4242',
        expiry='12/28',
        card_code='123'
    )
)

Accessing Object Attributes

Object attributes are accessible through dot notation.

customer.name

Updating an Object

Updating an object is a simple call to the update object method.

# Updating a customer's email
customer.update( email='matt.perez@newwork.com' )

Selecting Objects

Objects can be selected using any of their attributes.

# Select a customer by email
customers = pl.Customer.filter_by(
    email='matt.perez@example.com'
)

Use the pl.attr attribute helper interface to write powerful queries with a little extra syntax sugar.

payments = pl.Payment.filter_by(
    pl.attr.amount > 100,
    pl.attr.amount < 200,
    pl.attr.description.contains("Test"),
    pl.attr.created_at > datetime(2021,2,1)
).all()

Testing the Payload Python Library

Tests are contained within the tests/ directory. To run tests:

# Install dependencies
pdm install

# Run integration tests
TEST_SECRET_KEY=test_api_key pdm run pytest tests/int/

# Run unit tests
pdm run pytest tests/unit/

# Run a specific test file
TEST_SECRET_KEY=test_api_key pdm run pytest tests/int/test_transaction.py

Documentation

To get further information on Payload's Python library and API capabilities, visit the unabridged Payload Documentation.

Metadata

Release files for payload-api 0.5.1

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

Built distribution (wheel)

Table of built distributions (wheels) for payload-api 0.5.1
File Interpreter ABI Platform Actions
payload_api-0.5.1-py3-none-any.whl Python 3 none any Details for payload_api-0.5.1-py3-none-any.whl

Release files / payload_api-0.5.1-py3-none-any.whl

Download URL payload_api-0.5.1-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ba7c24f3f4a12790d239119a012d31e1b60bcaf892e45d2f26cb3996a40e01d
BLAKE2b-256 checksum
How to use checksums
13ef78beea11d76d69064cc5cdf84cdcac3532218193c3ad5d1843683c090997
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for payload-api 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.1 This release

1 release file No provenance

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