Last Updated: February 25, 2016
·
1.034K
· mrkschan

Rate limiting Shopify API using Cuttle Proxy

We can use sleep() to rate limit our calls to Shopify API. When we need to rate limit calls in multiple processes, sleep() does not work well enough.

In that case, we may use a HTTP proxy with outbound rate limit capability - https://github.com/mrkschan/cuttle. To do so, download Cuttle and use the config below:

# Download
GOPATH=`pwd` go get github.com/mrkschan/cuttle

# Config - cuttle.yml
addr: :3128
zones:
  - host: "*.myshopify.com"
    shared: false
    control: rps
    rate: 3

And, run it.

bin/cuttle -f cuttle.yml

Then, make API calls like below:

# client.py
import shopify

shop_url = 'https://{}:{}@{}/admin'.format(API_KEY, PASSWORD, SHOPIFY_DOMAIN)
shopify.ShopifyResource.set_site(shop_url)

print json.dumps(shopify.Shop.current().to_dict())

# Run
HTTPS_PROXY=127.0.0.1:3128 python client.py