Skip to main content

shoply

Shoply's API from your own server. Every route of the API reference is a method, with types your editor and mypy read, safe retries, lists a page at a time or all at once, and checking that a webhook came from Shoply.

pip install shoply

Python 3.9 or later. No dependencies.

import shoply

client = shoply.Client()  # SHOPLY_API_KEY from the environment

order = client.orders.show("ORDER_ID")

for customer in client.customers.list(search="gmail.com"):
    print(customer["emailAddress"])

coupon = client.coupons.create(code="SPRING10", value=10)

Make the key under Developers, API Keys in the dashboard, with the permissions your code needs. Keep it on your server.

A route's method is its id: Get an order is orders.show, so client.orders.show(order_id). The address's IDs come first, in order, then the fields as keyword arguments, by the names the reference gives them, then options. A field whose name is a Python keyword takes an underscore: from_.

Errors

A refusal is a shoply.ShoplyError, with status, code (not_found, missing_scope, validation_failed...), errors for each field that is wrong, and request_id.

try:
    client.coupons.create(code="SPRING10", value=10)
except shoply.ShoplyError as error:
    if error.code == "validation_failed":
        print(error.errors)

A change is sent with an Idempotency-Key, the same on every try, so a try whose answer was lost is never carried out twice. Pass idempotency_key=... to use your own.

Webhooks

import os

import shoply
from flask import Flask, request

app = Flask(__name__)


@app.post("/webhooks/shoply")
def shoply_webhook() -> tuple[str, int]:
    try:
        event = shoply.webhooks.verify(request.get_data(), request.headers, os.environ["SHOPLY_WEBHOOK_SECRET"])
    except shoply.ShoplyError:
        return "", 401

    if event["event"] == "order.paid":
        ...  # event["data"] is the order

    return "", 200

The Customer API

shoply.Customer signs a buyer in with a code emailed to them, and reads their own orders, keys and subscriptions. It holds the buyer's token and no key.

buyer = shoply.Customer("YOUR_STORE_ID")

buyer.login(email=email)
buyer.verify(email=email, code=code)
me = buyer.show()

OAuth

An app that sellers connect to their own stores gets a token by OAuth, and passes it as its key.

pkce = shoply.oauth.pkce()
url = shoply.oauth.authorize_url(client_id, redirect_uri, state=state, code_challenge=pkce["challenge"])

# Back at your redirect URL:
token = shoply.oauth.exchange(client_id=client_id, client_secret=client_secret, code=code, redirect_uri=redirect_uri, code_verifier=pkce["verifier"])
client = shoply.Client(token["access_token"], store_id=token["store_id"])

How apps work: https://docs.shoply.gg/guides/oauth

The whole guide: https://docs.shoply.gg/api-reference/python

Metadata

Release files for shoply 0.6.0

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

Source distribution (sdist)

Source distribution for shoply 0.6.0
File Size Uploaded Provenance Actions
shoply-0.6.0.tar.gz 118.7 kB Without provenance Details for shoply-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shoply 0.6.0
File Interpreter ABI Platform Actions
shoply-0.6.0-py3-none-any.whl Python 3 none any Details for shoply-0.6.0-py3-none-any.whl

Total release size: 235.5 kB

Release files / shoply-0.6.0.tar.gz

Download URL shoply-0.6.0.tar.gz
Size 118.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d1b51173c682016734938c7980a4552436c96fe6484d3105f184f87b146a3de5
BLAKE2b-256 checksum
How to use checksums
e96d3aed3b545d39af0f5f29e254e196b06e4e60a16b7e03ce77cbf7f6d90b3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / shoply-0.6.0-py3-none-any.whl

Download URL shoply-0.6.0-py3-none-any.whl
Size 116.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c1a45a8a641b887d4d1384566ca26d999282de9b9e39ace6bdf48eaed8a0b5d
BLAKE2b-256 checksum
How to use checksums
d2761d7a144792ac67c7b5a5b3f59db801fe2b337e731f9877083714d697c4a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for shoply 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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