Skip to main content

Payload Python Library

Project description

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')

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'
    )
)

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 a test file, once within the pipenv shell, enter the command in terminal

TEST_SECRET_KEY=test_api_key pytest tests/{__FILENAME__}.py

Documentation

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

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

payload-api-0.4.10.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

payload_api-0.4.10-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file payload-api-0.4.10.tar.gz.

File metadata

  • Download URL: payload-api-0.4.10.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for payload-api-0.4.10.tar.gz
Algorithm Hash digest
SHA256 d1d00b7b0fbceb4645862b42661ada1d395a41c726dd18c0ce0fc2d79a8d977a
MD5 bddd86e485654bf4b94052c301a7ee6a
BLAKE2b-256 300218b20a08329cc4583680e954529a5fd988f12f247d0e8eb62dffd20a11c1

See more details on using hashes here.

File details

Details for the file payload_api-0.4.10-py3-none-any.whl.

File metadata

File hashes

Hashes for payload_api-0.4.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1c5f30e091997fc59b374eb01a3e3c61d1ed2ab7eea6106febb009f5aba8930b
MD5 2a8ae796275a286a15259bdd88e37db2
BLAKE2b-256 d0c25c0570c9ce7302677fa833b371de2ee0c3a62d5bda4015191bf4b7c2640e

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