Install & Compatibility
Where this runs
tested against v12.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.406s · 23MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.5s · import 0.388s · 24MB
21MB installed
● package 21MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
shopify
✓ import shopify
The main library is imported as 'shopify'.
Session
✓ from shopify import Session
Used for establishing API connection.
ShopifyResource
✓ from shopify import ShopifyResource
Used for activating the API session.
This quickstart demonstrates how to authenticate with the Shopify API using a private app's API key and password, activate a session, and perform basic operations like fetching shop details and making a GraphQL query. Remember to set your `SHOPIFY_API_KEY`, `SHOPIFY_PASSWORD`, `SHOPIFY_SHOP_NAME`, and `SHOPIFY_API_VERSION` environment variables or replace the placeholder values. Shopify recommends using GraphQL for new development.
import os
import shopify
# --- Configuration from Environment Variables ---
# For a Private App, you need API Key and Password
SHOPIFY_API_KEY = os.environ.get('SHOPIFY_API_KEY', 'your_api_key')
SHOPIFY_PASSWORD = os.environ.get('SHOPIFY_PASSWORD', 'your_password')
SHOPIFY_SHOP_NAME = os.environ.get('SHOPIFY_SHOP_NAME', 'your-shop-name') # e.g., 'my-awesome-store'
SHOPIFY_API_VERSION = os.environ.get('SHOPIFY_API_VERSION', '2024-07') # Use a stable, supported API version
# Construct the shop URL for a private app
shop_url = f"https://{SHOPIFY_API_KEY}:{SHOPIFY_PASSWORD}@{SHOPIFY_SHOP_NAME}.myshopify.com/admin"
# Set up the API session
shopify.ShopifyResource.set_site(shop_url)
shopify.ShopifyResource.set_api_version(SHOPIFY_API_VERSION)
try:
# Activate a temporary session to make calls
with shopify.Session.temp(shop_url, SHOPIFY_API_VERSION):
# Example: Fetching the current shop's details
shop = shopify.Shop.current()
print(f"Connected to shop: {shop.name} (ID: {shop.id})")
# Example: Fetching a product by ID (replace with a real product ID from your store)
# product_id = 1234567890123 # Replace with an actual product ID
# try:
# product = shopify.Product.find(product_id)
# print(f"Found product: {product.title} (ID: {product.id})")
# except Exception as e:
# print(f"Could not find product {product_id}: {e}")
# Example: Making a GraphQL query (Recommended for new development)
graphql_client = shopify.GraphQL()
query = """
query {
shop {
name
id
}
}
"""
result = graphql_client.execute(query)
print(f"GraphQL Shop Info: {result}")
except shopify.pyactiveresource.connection.ClientError as e:
print(f"API Client Error: {e.response.code} - {e.response.message}")
print("Check your API Key, Password, Shop Name, and API Version.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
shopify --version
Debug
Known issues
breakingShopify APIs undergo quarterly version updates, which frequently introduce breaking changes, deprecations, and structural modifications. These can directly impact existing `shopifyapi` integrations. For instance, the '2024-04' version deprecated specific REST API endpoints and changed how products are published/unpublished.fixSubscribe to the Shopify Developer Changelog and regularly review API release notes for your target API version. Plan for quarterly maintenance to update your integration code as needed.
affects: All versions, as it depends on the specific Shopify API version used.
breakingThe `InventoryAdjustQuantityMutation` in the Admin API has been deprecated and replaced with `InventoryBulkAdjustQuantityAtLocation`. Similarly, direct product publish/unpublish actions are deprecated in favor of publishing/unpublishing to specific sales channels.fixMigrate to `InventoryBulkAdjustQuantityAtLocation` for inventory adjustments and use the 'Publish to Sales Channels' or 'Unpublish from Sales Channels' actions for product visibility management.
affects: Shopify API versions 2024-04 and later.
deprecatedShopify generally recommends using the GraphQL API for new development, as the REST API is subject to deprecation in the future.fixPrioritize GraphQL API for new features and consider migrating existing REST API calls to GraphQL where feasible to ensure long-term compatibility.
affects: All versions, especially for new integrations.
breakingThe Checkout API is being fully deprecated. This is a significant change impacting how custom checkout experiences are built.fixMigrate to the Storefront Cart API or Checkout Sheet Kit before the deprecation deadline.
affects: Shopify API version 2025-04-01 and later.
gotchaWhen setting up `shopify.Session` or `shopify.ShopifyResource.set_site()`, ensure you provide the correct API version. Using an unsupported or incorrect API version will lead to connection errors.fixAlways explicitly specify a currently supported API version (e.g., '2024-07') in your code. Consult Shopify's API documentation for valid versions.
affects: All versions.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'shopify'
The `shopifyapi` Python package (which provides the `shopify` module for import) has not been installed in your environment.
fixInstall the library using pip: `pip install shopifyapi`
pyactiveresource.exceptions.ClientError: Response (401 Unauthorized)
The API key, secret, or access token provided for authentication is invalid, expired, or lacks the necessary permissions for the Shopify store.
fixVerify your API credentials (key, secret, access token, shop URL, and scopes) and ensure they are correct and active for the target Shopify store.
DeprecationWarning: 'shopify.api_version' is deprecated. Use 'shopify.ShopifyResource.set_api_version' instead.
You are using the older, deprecated method `shopify.api_version = '...'` to set the Shopify API version, which has been replaced by a class method.
fixUpdate your code to use `shopify.ShopifyResource.set_api_version('YOUR_API_VERSION')` (e.g., `'2024-04'`) for the desired Shopify API version. AttributeError: 'NoneType' object has no attribute 'id'
This error typically occurs when a Shopify resource lookup (e.g., `shopify.Product.find()`) fails to find a matching resource and returns `None`, and subsequent code attempts to access attributes on this `None` object without checking.
fixAlways check if the result of a resource lookup is not `None` before attempting to access its attributes. Example: `product = shopify.Product.find(123); if product: print(product.id)`
Upgrade
Version history
12.7.0latest on PyPI · released Nov 4, 2024
Audit
Dependencies
pyactiveresourcerequiredCore dependency for ActiveResource-like interface.