Every year my accountant asks for a inventory run down of my online store that runs on Shopify. So I decided to make my life easier on June 30th and write this Python script to do all the hard work for me.
It uses a variety of GraphQL calls to get the data. The reference of which is available here and I used the Shopify GraphiQL App Docs sidebar which I found to be a useful tool during development.
It takes a single argument for the output file (-out). The default is inventory.csv.
inventory.py -out
We will be using:
- Progress to display the progress of the scrip to the user.
- python-dotenv to read and use the environment variables
- Shopify API to access the Shopify Admin API in Python.
To install these packages, you should use Python's package installer, pip3. On the MacOS CLI you can use these commands:
pip3 install progress
pip3 install python-dotenv
pip3 install ShopifyAPI
This project includes an example of a .env files that you need to create to allow you to acccess your private Shopify App. You need to fill out your API key and API secret KEY before copying it to .env.
cp .env.local .env
If this is the first time you are running requests using SSL, you might numerous errors on the CLI when running the Python file such as:
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED]
If this is the case, as it was for me, check out the following stackoverflow.com answer that helped solve the issue for me.