Skip to main content

Shopify GraphQL Helper

PyPI TestPyPI Python Versions License: MIT CI Publish GitHub Release

Tiny, production‑minded helpers for the Shopify Admin GraphQL API. Shopify's official Python SDK exposes GraphQL().execute only; this package adds sessions, automatic cursor pagination, and per‑shop throttling.

Features:

  • 🚀 Simple, focused API for Shopify GraphQL Admin API
  • 🔄 Automatic cursor-based pagination
  • ⚡ Built-in request throttling
  • 🔒 Thread-safe implementation
  • 🧩 Transport layer abstraction

Note: This is not an official Shopify package.

Installation

pip install shopify-gql-helper

Quickstart

query = """
query ($first:Int!, $after:String) {
  products(first:$first, after:$after, query:"status:ACTIVE") {
    pageInfo { hasNextPage endCursor }
    nodes { id legacyResourceId title handle }
  }
}
"""

from shopify_gql_helper import ShopifySession, execute, cursor_pages

session = ShopifySession("https://example.myshopify.com", "shpca_123")

# One-off request
data = execute(session, query, {"first": 1})

# Stream all products
for product in cursor_pages(session, query, ["data", "products"]):
    print(product["id"], product["title"])

connection_path lists the keys from the response root to the desired connection, so ["data", "products"] points to data.products above. Additional GraphQL variables can be supplied via the optional variables argument.

Throttling

Shopify uses a leaky bucket policy. ShopifySession coordinates requests per shop through a shared ThrottleController. Adjust min_bucket (default 50) and min_sleep (default 1.0s) to tune how aggressively you consume the bucket. Reuse a single ShopifySession per shop to avoid fighting the throttling limits.

Configuration

ShopifySession

from shopify_gql_helper import ShopifySession

# Required parameters
session = ShopifySession(
    shop_url="https://your-store.myshopify.com",
    access_token="shpca_your_access_token"
)

# Optional parameters
session = ShopifySession(
    shop_url="https://your-store.myshopify.com",
    access_token="shpca_your_access_token",
    api_version="2025-01",  # default
    min_bucket=50,          # minimum available requests before throttling
    min_sleep=1.0,          # minimum sleep time between requests (seconds)
)

Throttling

Shopify uses a leaky bucket policy. ShopifySession coordinates requests per shop through a shared ThrottleController.

Important: Reuse a single ShopifySession per shop to properly respect rate limits.

Retries

Requests use a thread-local requests.Session with urllib3's Retry to handle connect/read errors and 429/5xx responses with exponential backoff. Retry counts can be tuned via SHOPIFY_GQL_RETRIES or RequestsTransport(retries=...). A small amount of random jitter is added to backoff delays (configurable via SHOPIFY_GQL_JITTER or RequestsTransport(jitter=...)), and Retry-After headers are honored. By default, a Connection: close header is sent with each request; pass force_close=False to RequestsTransport to enable persistent connections.

Custom Transport

You can provide a custom transport that implements the Transport protocol:

from shopify_gql_helper.transport import Transport

class CustomTransport(Transport):
    def post(self, url: str, headers: dict, json: dict, timeout: float):
        raise NotImplementedError

Development

# Install with development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=shopify_gql_helper

Limitations / Roadmap

  • Bulk operations
  • Nested pagination (e.g., products → variants)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


This project is not affiliated with Shopify Inc. Shopify is a registered trademark of Shopify Inc.

MIT. Not affiliated with Shopify.

Metadata

Release files for shopify-gql-helper 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shopify-gql-helper 0.1.3
File Size Uploaded
shopify_gql_helper-0.1.3.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shopify-gql-helper 0.1.3
File Interpreter ABI Platform
shopify_gql_helper-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / shopify_gql_helper-0.1.3.tar.gz

Download URL shopify_gql_helper-0.1.3.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6bc558b9dca4a5d307b9ebfe018faf1e6be0bc59c1882e92c37d4e6afe0219d6
BLAKE2b-256 checksum
How to use checksums
819f46b2b9c620fa82dd00952e23490678cf9d2349ec5266c00f23865b644acf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2025.

Transparency log

Release files / shopify_gql_helper-0.1.3-py3-none-any.whl

Download URL shopify_gql_helper-0.1.3-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ebc6c23d2a8bb6e2c381975bb89afd9c159c9e59897a75a6b8310edfdbe9c04
BLAKE2b-256 checksum
How to use checksums
be8b71e87489348f615a7290f222ec3b68bb5cc643a11ce0d945772e87d1f99a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page