Package: bigcommerce
Wrapper over therequestslibrary for communicating with the Bigcommerce v2 API.Install withpip install bigcommerceoreasy_install bigcommerce. Tested with
python 3.7-3.9, and only requiresrequestsandpyjwt.UsageConnectingimportbigcommerce# 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'))BigcommerceApialso 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, configuresapito be ready for use.BigcommerceApi.oauth_verify_payload(signed_payload, client_secret)– Returns user data from a signed payload.Accessing and objectsTheapiobject 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/1api.Products.create(name='',type='',...)# POST /productsapi.Products.get(1).update(price='199.90')# PUT /products/1api.Products.delete_all()# DELETE /productsapi.Products.get(1).delete()# DELETE /products/1api.Products.count()# GET /products/countThe 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/2And 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/1These subresources implement CRUD methods in exactly the same way as
regular resources:api.Products.get(1).options(1).delete()FiltersFilters can be applied toallmethods as keyword arguments:customer=api.Customers.all(first_name='John',last_name='Smith')[0]orders=api.Orders.all(customer_id=customer.id)Error handlingMinimal validation of data is performed by the client, instead deferring
this to the server. AHttpExceptionwill be raised for any unusual
status code:3xx status code:RedirectionException4xx status code:ClientRequestException5xx status code:ServerExceptionThe low level APIThe high level API provided bybigcommerce.api.BigcommerceApiis a
wrapper around a lower level api inbigcommerce.connection. This can
be accessed throughapi.connection, and provides helper methods for
get/post/put/delete operations.Accessing V3 API endpointsAlthough 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 APIThere 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 LimitsYou can optionally pass arate_limiting_managementobject intobigcommerce.api.BigcommerceApiorbigcommerce.connection.OAuthConnectionfor automatic rate limiting management, ex:importbigcommerceapi=bigcommerce.api.BigcommerceApi(client_id='',store_hash='',access_token=''rate_limiting_management={'min_requests_remaining':2,'wait':True,'callback_function':None})min_requests_remainingwill determine the number of requests remaining in the rate limiting window which will invoke the management functionwaitdetermines whether or not we should automatically sleep until the end of the windowcallback_functionis a function to run when the rate limiting management function fires. It will be invokedafterthe wait, if enabled.callback_argsis 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 amin_requests_remaininghigher than your concurrency, and not use the default wait function.Further documentationFull documentation of the API is available on the BigcommerceDeveloper PortalTo doAutomatic enumeration of multiple page responses for subresources.