Skip to main content

Tiny, production-minded helper for the Shopify Admin GraphQL API

Project description

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shopify_gql_helper-0.1.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shopify_gql_helper-0.1.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file shopify_gql_helper-0.1.2.tar.gz.

File metadata

  • Download URL: shopify_gql_helper-0.1.2.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shopify_gql_helper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7f8131b075f24864786d6aa345cf9bc047d507a2fca08f116104bf5ba5971124
MD5 8b989f3228b0dfe2c1dd16cdb3a1a88e
BLAKE2b-256 34011108c6c824df90738a0b319347223e1a1718e5ee4b0c9d8922f1d9d09c40

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopify_gql_helper-0.1.2.tar.gz:

Publisher: upload-python-package.yml on tulayha/shopify-gql-helper-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shopify_gql_helper-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for shopify_gql_helper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cec40e234308c77abf4dd9a34c9590ce826c369517adcaa8a4dd7c35e9b6a48c
MD5 e288eafac718f2f7ec6aee8dff761f9f
BLAKE2b-256 c5eff7beb93ecb02041cadd58add5488600659589b0c0d0918902dab3adf8f80

See more details on using hashes here.

Provenance

The following attestation bundles were made for shopify_gql_helper-0.1.2-py3-none-any.whl:

Publisher: upload-python-package.yml on tulayha/shopify-gql-helper-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page