Skip to main content

Bigcommerce API Python Client

Build Status Package Version

Wrapper over the requests library for communicating with the Bigcommerce v2 API.

Install with pip install bigcommerce or easy_install bigcommerce. Tested with python 3.7-3.9, and only requires requests and pyjwt.

Usage

Connecting

import bigcommerce

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

# Private apps (Basic Auth)
api = bigcommerce.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 /products (returns only a single page of products as a list)
api.Products.iterall()                     # GET /products (autopaging generator that yields all
                                           #                  products from all pages product by product.)
api.Products.get(1)                        # GET /products/1
api.Products.create(name='', type='', ...) # POST /products
api.Products.get(1).update(price='199.90') # PUT /products/1
api.Products.delete_all()                  # DELETE /products
api.Products.get(1).delete()               # DELETE /products/1
api.Products.count()                       # GET /products/count

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

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

And as helper methods on the parent resource:

api.Products.get(1).options()              # GET /products/1/options
api.Products.get(1).options(1)             # GET /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

  • 5xx status code: ServerException

The low level API

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

Accessing V3 API endpoints

Although this library currently only supports high-level modeling for V2 API endpoints, it can be used to access V3 APIs using the OAuthConnection object:

v3client = bigcommerce.connection.OAuthConnection(client_id=client_id,
                                                  store_hash=store_hash,
                                                  access_token=access_token,
                                                  api_path='/stores/{}/v3/{}')
v3client.get('/catalog/products', include_fields='name,sku', limit=5, page=1)

Accessing GraphQL Admin API

There is a basic GraphQL client which allows you to submit GraphQL queries to the GraphQL Admin API.

gql = bigcommerce.connection.GraphQLConnection(
    client_id=client_id,
    store_hash=store_hash,
    access_token=access_token
)
# Make a basic query
time_query_result = gql.query("""
    query {
      system {
        time
      }
    }
""")
# Fetch the schema
schema = gql.introspection_query()

Managing Rate Limits

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

import bigcommerce

api = bigcommerce.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

  • Automatic enumeration of multiple page responses for subresources.

Release files for bigcommerce 0.23.4

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

Source distribution (sdist)

Source distribution for bigcommerce 0.23.4
File Size Uploaded
bigcommerce-0.23.4.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bigcommerce 0.23.4
File Interpreter ABI Platform
bigcommerce-0.23.4-py3-none-any.whl Python 3 none any Details

Total release size: 48.6 kB

Release files / bigcommerce-0.23.4.tar.gz

Download URL bigcommerce-0.23.4.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bc0bcc981a80bb78ac5406d230666c8f7d5a5ebbbb896c41341f80945efe7a85
BLAKE2b-256 checksum
How to use checksums
7b7a3e33b6dfc83b279d93e522b2f4ff27d884c20840a86a40c0b6e7c3ec5144
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / bigcommerce-0.23.4-py3-none-any.whl

Download URL bigcommerce-0.23.4-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5668ff171a2cf856e6dca3bd2e1a05b5e1cf10d964faebf83ce6eda316846a7
BLAKE2b-256 checksum
How to use checksums
ddbb94a2203c1beb08331817d407f0fcc4d4c79582d7e64fff71fe56f30bbf1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.23.4 This release

2 release files

0.23.3

2 release files

0.23.2

2 release files

0.22.3

2 release files

0.22.2

1 release file

0.22.1

1 release file

0.22.0

1 release file

0.20.1

2 release files

0.20.0

1 release file

0.19.1

2 release files

0.19.0

1 release file

0.18.2

1 release file

0.18.1

1 release file

0.18.0

1 release file

0.17.3

2 release files

0.17.2

1 release file

0.17.1

2 release files

0.17.0

1 release file

0.16.0

2 release files

0.15.0

1 release file

0.14.0

2 release files

0.13.0

1 release file

0.11.0

1 release file

0.10.2

1 release file

0.0.1

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