Skip to main content

Client for the Button API

Project description

This module is a thin client for interacting with Button’s API.

Please see the full API Docs for more information. For help, check out our Support page or get in touch.

Supported runtimes

  • cPython 2.6, 2.7, 3.2, 3.3, 3.4, 3.5

Dependencies

  • None

Usage

pip install pybutton

To create a client capable of making network requests, instantiate a pybutton.Client with your API key.

from pybutton import Client

client = Client('sk-XXX')

The client will always attempt to raise a pybutton.ButtonClientError in an error condition.

All API requests will return a pybutton.response.Response instance, which supports accessing data properties from the API response as attributes. To access the raw response dict, use #to_dict. For instance:

from pybutton import Client
from pybutton import ButtonClientError

client = Client("sk-XXX")

try:
    response = client.orders.get("btnorder-XXX")
except ButtonClientError as e:
    print(e)

print(response)
# <class pybutton.Response status: open, btn_ref: None, line_items: [], ...>

print(response.status)
# 'open'

print(response.to_dict())
# {'status': open, 'btn_ref': None, 'line_items': [], ...}

Configuration

You may optionally supply a config argument with your API key:

from pybutton import Client

client = Client("sk-XXX", {
  'hostname': 'api.testsite.com',
  'port': 80,
  'secure': False,
  'timeout': 5, # seconds
})

The supported options are as follows:

  • hostname: Defaults to api.usebutton.com.

  • port: Defaults to 443 if config.secure, else defaults to 80.

  • secure: Whether or not to use HTTPS. Defaults to True. N.B: Button’s API is only exposed through HTTPS. This option is provided purely as a convenience for testing and development.

  • timeout: The time in seconds that may elapse before network requests abort. Defaults to None.

Resources

We currently expose only one resource to manage, Orders.

Orders

n.b: all currency values should be reported in the smallest possible unit of that denomination, i.e. $1.00 should be reported as 100 (i.e. 100 pennies)

Create
from pybutton import Client

client = Client('sk-XXX')

response = client.orders.create({
    'total': 50,
    'currency': 'USD',
    'order_id': '2007',
    'finalization_date': '2017-08-02T19:26:08Z',
})

print(response)
# <class pybutton.Response total: 50, currency: 'USD', ...>
Get
from pybutton import Client

client = Client('sk-XXX')

response = client.orders.get('btnorder-XXX')

print(response)
# <class pybutton.Response total: 50, currency: 'USD', ...>
Update
from pybutton import Client

client = Client('sk-XXX')

response = client.orders.update('btnorder-XXX', {
    'total': 60,
})

print(response)
# <class pybutton.Response total: 60, currency: 'USD', ...>
Delete
from pybutton import Client

client = Client('sk-XXX')

response = client.orders.delete('btnorder-XXX')

print(response)
# <class pybutton.Response >

Contributing

  • Building the egg: python setup.py bdist_egg

  • Building the wheel: python setup.py bdist_wheel --universal

  • Building the sdist: python setup.py sdist

  • Installing locally: python setup.py install

  • Running tests: python setup.py test

  • Running lint: flake8

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

pybutton-1.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybutton-1.1.0-py2-none-any.whl (11.7 kB view details)

Uploaded Python 2

File details

Details for the file pybutton-1.1.0.tar.gz.

File metadata

  • Download URL: pybutton-1.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pybutton-1.1.0.tar.gz
Algorithm Hash digest
SHA256 8a0ce6094fe6765ea622bc97ad1e15d22f47aca72b61c07d139cb8fbb6c1c90f
MD5 d5e21ce4e3c64b899baddf99de6dd7c6
BLAKE2b-256 11dc1a955715cd3a2dd10a47b807df9145bf7dd75cea77de95f6d7f05cac2c25

See more details on using hashes here.

File details

Details for the file pybutton-1.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pybutton-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 0b0b1a8cb6daace44416168cdd040b9f67833bdf374f369703bb7eb150145b78
MD5 190b85482768ea6b924282bc074937f6
BLAKE2b-256 19d97a4735c45397d62d9b7c9123324f444172e04afb84996061277239226b05

See more details on using hashes here.

Supported by

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