This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
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 two resources to manage, Orders and Accounts.

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 >

Accounts

All
from pybutton import Client

client = Client('sk-XXX')

response = client.accounts.all()

print(response)
# <class pybutton.Response [2 elements]>
Transactions

Along with the required account ID, you may also pass the following optional arguments:

  • cursor (string): An API cursor to fetch a specific set of results.
  • start (ISO-8601 datetime string): Fetch transactions after this time.
  • end (ISO-8601 datetime string): Fetch transactions before this time.
from pybutton import Client

client = Client('sk-XXX')

response = client.accounts.transactions(
    'acc-123',
    start='2016-07-15T00:00:00.000Z',
    end='2016-09-30T00:00:00.000Z'
)

print(response)
# <class pybutton.Response [100 elements]>

Response

Methods

data

from pybutton import Client

client = Client('sk-XXX')

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

print(response.data())
# {'total': 50, 'currency': 'USD', 'status': 'open' ... }

response = client.accounts.all()

print(response.data())
# [{'id': 'acc-123', ... }, {'id': 'acc-234', ... }]

next_cursor

For any paged resource, next_cursor() will return a cursor to supply for the next page of results. If next_cursor() returns None, there are no more results.

from pybutton import Client

client = Client('sk-XXX')

response = client.accounts.transactions('acc-123')
cursor = response.next_cursor()

# loop through and print all transactions
while cursor:
    response = client.accounts.transactions('acc-123', cursor=cursor)
    print(response.data())
    cursor = response.next_cursor()

prev_cursor

For any paged resource, prev_cursor() will return a cursor to supply for the next page of results. If prev_cursor() returns None, there are no more previous results.

from pybutton import Client

client = Client('sk-XXX')

response = client.accounts.transactions('acc-123', cursor='xyz')

print(response)
# <class pybutton.Response [25 elements]>

cursor = response.prev_cursor()

response = client.accounts.transactions('acc-123', cursor=cursor)

print(response)
# <class pybutton.Response [100 elements]>

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
Release History

Release History

2.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pybutton-2.0.0-py2-none-any.whl (14.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Oct 13, 2016
pybutton-2.0.0.tar.gz (10.6 kB) Copy SHA256 Checksum SHA256 Source Oct 13, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting