Skip to content

3 Simple Steps to Manage An eCommerce Store with Python Using the Shopify API – Even If You’re A Beginner

Today, I’m sharing three simple tips to manage a Shopify store with Python.

As a data analyst, one of the best ways to stand out from the crowd is to become a specialist in one specific technology. If you can work with Shopify using Python you have a leg up on other data analysts that don’t have this expertise. Put yourself in a business owner’s shoes: would you rather hire someone with a specific skillset or a more general skill set?

Unfortunately, most data analysts never pick a specialty and get passed up for performance marketing analytics jobs all the time.

eCommerce is BOOMING and store owners need data experts like you.

Many data analysts won’t make an effort to learn this specialized skill, and the list of excuses is endless:

  • Python is too hard
  • eCommerce is boring
  • I don’t know where to start
  • I’m not an expert and nobody will hire me

But Python is the ultimate tool for solving problems for eCommerce store owners.

By the end of this guide you will:

  1. Be able to connect to a Shopify store
  2. Add new products
  3. Update existing products

And I’ll provide a Python notebook that you can copy to experiment on your own.

Step 1: Connecting to your store via the Shopify API using Python

If you don’t already have a Shopify dev store, I put together a full write-up:

The entire process takes less than an hour from start to finish.

Once you have your store, here’s how you connect using Python.

  1. Install and import the Python Shopify API library
  2. Configure your store connection
    1. URL
    2. Admin API key
    3. API version
  3. Create and activate a new session

Here’s the code to connect to your Shopify store using Python

# Install and import on Google Colab
!pip install ShopifyAPI
import shopify

# Configure store details
shop_url = 'yourstorename.myshopify.com'
admin_api_key = 'your_secret_admin_api_key'
api_version = '2022-07'

# Create and activate a new session
session = shopify.Session(shop_url, api_version, admin_api_key)
shopify.ShopifyResource.activate_session(session)

If you’ve done everything correctly, you should be able to search for product details using find:

# Get product title for a specific product ID
# Your product ID will be different
product = shopify.Product.find(8017472717077)
print(f'The title of this product is "{product.title}".')

Once you’re connected you can add new products!

Step 2: Adding a new product

Adding new products to Shopify via the Admin API with Python can be done in just 3 lines of code:

# Create a new product Object, set the title, save to Shopify
new_product = shopify.Product()
new_product.title = 'Hiking Club Crewneck'
new_product.save() 

If you’ve created a new product, you’ll be able to see it in your Shopify store!

Now we can update products using the Shopify API

Step 3: Updating existing products

Updating products in Shopify with the Python API also takes a few lines of code:

crewneck = shopify.Product.find(8024192516373)
crewneck.body_html = "A very special crewneck covered in patches."
crewneck.save()

If you want to see all of the attributes for a product just use Product.attributes to get a JSON object with all of the product details.

# Command
crewneck.attributes

# Returns a JSON object with all details
{'id': 8024192516373,
 'title': 'Hiking Club Crewneck',
 'body_html': 'A very special crewneck covered in patches.',
 'vendor': 'NewPredictionDev',
 'product_type': '',
 'created_at': '2022-12-03T09:14:06-05:00',
 'handle': 'hiking-club-crewneck',
 'updated_at': '2022-12-03T09:33:03-05:00',
 'published_at': '2022-12-03T09:14:06-05:00',
 'template_suffix': None,
 'status': 'active',
 'published_scope': 'web',
 'tags': '',
 'admin_graphql_api_id': 'gid://shopify/Product/8024192516373',
 'variants': [variant(43961148440853)],
 'options': [option(10194979291413)],
 'images': [],
 'image': None,
 'price': 55.0}

That’s it!

Here’s a copy of my notebook with all of my code for this guide.

Shopify is an amazing eCommerce platform and the API gives you the power to do anything you want using Python.

That’s it for today – I hope you enjoyed it.

See you again next week!


Whenever you’re ready, here are 3 ways I can help you:

  1. View all past issues of my newsletter here.
  2. If you’re ready to build your online data analytics portfolio, my 14-day Data Analytics Portfolio Playbook is for you.
  3. If you want actionable data analytics advice on your specific situation, book a 1:1 coaching session with me today.

Leave a Reply

Your email address will not be published. Required fields are marked *

Tableau & Google Sheets Checklist

This one-page checklist PDF will help you learn how to upload your data into Google Sheets and build an awesome Tableau dashboard without wasting time.

You have Successfully Subscribed!

4 Things For Every Tableau Dashboard Creator

This free 4-page eBook PDF will walk you through the 4 most important steps for creating a Tableau dashboard

You have Successfully Subscribed!

Massive List of Tableau Tools

Tableau is even more powerful with these 20 tools you might not know about. The 2-page PDF includes a description and helpful links for each tool to get you started.

You have Successfully Subscribed!

Career Boosting Business Analytics Trends

Use this list as a road map to take you from boring data job to the GO-TO PERSON in your company that knows the answers to all the questions.

All set! Check your email :)

Massive List of Free Data Viz Books

List of 10 Awesome Data Visualization Books

All set! Check your email to download.

Tableau Dashboards
Beginner’s Guide

Get the full 2-page PDF with the 5 steps outlined in this guide + 3 bonuses to help you along the way

BONUS #1: 5 Beginner mistakes to avoid

BONUS #2: Video walkthrough

BONUS #3: Links to the the Google Sheet and final Dashboard

All set! Check your email :)

How to Create 6 Different Tableau Bar Charts (Free Guide)

Get the step-by-step guide to create all 6 different types of Tableau Bar Charts (with copy-and-paste calculated fields included) for free.

 

All set! Check your email :)

Massive List of Tableau Web Data Connectors

Download the list of 21 different Web Data Connectors for Tableau in this Google Sheet (save a copy for yourself, too!) 

All set! Check your email :)

Slope Graph Examples PDF + Dashboard Walkthrough Video

4-page PDF showing 10 slope graph examples + a video walkthrough

All set! Check your email to download the bonus materials.

Tableau Tutorial Chart Redesign

Download the Tableau Tutorial PDF Checklist & Workbook

The step-by-step checklist for fixing busted charts with Tableau PLUS the full workbook with all of my formatting and calculations for free.

All set! Check your email to download.

Download the TableauHighlight Tables PDF Guide

The step-by-step guide for creating Tableau highlight tables
(plus direct links to the YouTube video walkthrough and link to final Tableau workbook)

You have Successfully Subscribed!

Tableau Scatter Plots: The Complete Guide

Get the step-by-step checklist guide to create scatter plots with Tableau

 

All set! Check your email :)

Rebuild a Busted Chart with Tableau

Enter your best email to get the PDF version of this tutorial + the companion Tableau workbook for free

All set! Check your email to download.

Download the Bonus Materials

Enter your best email to get the PDF checklist version of this guide and the companion Tableau workbook for free.

All set! Check your email :)