Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Connect Python applications with the Bigcommerce API

Project description

Wrapper over the bigcommerce library to support Bigcommerce v3 API.

Install with pip install bigcommerce_v3 or easy_install bigcommerce_v3. Tested with python 2.7, 3.4, 3.5, 3.6 and 3.7.

Usage

Connecting

import bigcommerce_v3

# Public apps (OAuth)
# Access_token is optional, if you don't have one you can use oauth_fetch_token (see below)
api = bigcommerce_v3.api.BigcommerceApi(client_id='', store_hash='', access_token='')

# Private apps (Basic Auth)
api = bigcommerce_v3.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('username', 'api token'))

BigcommerceApi also provides two helper methods for connection with OAuth2:

  • api.oauth_fetch_token(client_secret, code, context, scope, redirect_uri) – fetches and returns an access token for your application. As a side effect, configures api to be ready for use.
  • BigcommerceApi.oauth_verify_payload(signed_payload, client_secret) – Returns user data from a signed payload.

Accessing and objects

The api object provides access to each API resource, each of which provides CRUD operations, depending on capabilities of the resource:

api.Products.all()                         # GET /catalog/products (returns only a single page of products as a list)
api.Products.iterall()                     # GET /catalog/products (autopaging generator that yields all
                                           #                  products from all pages product by product.)
api.Products.get(1)                        # GET /catalog/products/1
api.Products.create(name='', type='', ...) # POST /catalog/products
api.Products.get(1).update(price='199.90') # PUT /catalog/products/1
api.Products.delete_all()                  # DELETE /catalog/products
api.Products.get(1).delete()               # DELETE /catalog/products/1
api.Products.count()                       # GET /catalog/products/count

The client provides full access to subresources, both as independent resources:

api.ProductOptions.get(1)                  # GET /catalog/products/1/options
api.ProductOptions.get(1, 2)               # GET /catalog/products/1/options/2

And as helper methods on the parent resource:

api.Products.get(1).options()              # GET /catalog/products/1/options
api.Products.get(1).options(1)             # GET /catalog/products/1/options/1

These subresources implement CRUD methods in exactly the same way as regular resources:

api.Products.get(1).options(1).delete()

Filters

Filters can be applied to all methods as keyword arguments:

customer = api.Customers.all(first_name='John', last_name='Smith')[0]
orders = api.Orders.all(customer_id=customer.id)

Error handling

Minimal validation of data is performed by the client, instead deferring this to the server. A HttpException will be raised for any unusual status code:

  • 3xx status code: RedirectionException
  • 4xx status code: ClientRequestException

The low level API

The high level API provided by bigcommerce_v3.api.BigcommerceApi is a wrapper around a lower level api in bigcommerce_v3.connection. This can be accessed through api.connection, and provides helper methods for get/post/put/delete operations.

Managing OAuth Rate Limits

You can optionally pass a rate_limiting_management object into bigcommerce_v3.api.BigcommerceApi or bigcommerce_v3.connection.OAuthConnection for automatic rate limiting management, ex:

import bigcommerce_v3

api = bigcommerce_v3.api.BigcommerceApi(client_id='', store_hash='', access_token=''
                                     rate_limiting_management= {'min_requests_remaining':2,
                                                                'wait':True,
                                                                'callback_function':None})

min_requests_remaining will determine the number of requests remaining in the rate limiting window which will invoke the management function

wait determines whether or not we should automatically sleep until the end of the window

callback_function is a function to run when the rate limiting management function fires. It will be invoked after the wait, if enabled.

callback_args is an optional parameter which is a dictionary passed as an argument to the callback function.

For simple applications which run API requests in serial (and aren’t interacting with many different stores, or use a separate worker for each store) the simple sleep function may work well enough for most purposes. For more complex applications that may be parallelizing API requests on a given store, it’s adviseable to write your own callback function for handling the rate limiting, use a min_requests_remaining higher than your concurrency, and not use the default wait function.

Further documentation

Full documentation of the API is available on the Bigcommerce Developer Portal

To do

For now just support Catalog APIs.

  • Add Price Lists API, Subscribers API, Scripts API, Themes API, BigCommerce Widgets API, Order, Transactions API, Payments API support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
bigcommerce_v3-0.1.3-py2.py3-none-any.whl (15.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page