{"id":13546376,"url":"https://github.com/Shopify/shopify_python_api","last_synced_at":"2025-04-02T18:30:38.234Z","repository":{"id":651415,"uuid":"2249127","full_name":"Shopify/shopify_python_api","owner":"Shopify","description":"ShopifyAPI library allows Python developers to programmatically access the admin section of stores","archived":false,"fork":false,"pushed_at":"2025-01-20T14:52:22.000Z","size":940,"stargazers_count":1336,"open_issues_count":27,"forks_count":370,"subscribers_count":536,"default_branch":"main","last_synced_at":"2025-04-01T22:16:40.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://shopify.github.io/shopify_python_api","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shopify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-08-22T14:49:21.000Z","updated_at":"2025-04-01T10:52:24.000Z","dependencies_parsed_at":"2024-01-10T21:59:59.892Z","dependency_job_id":"d48a39bd-5ebf-4a8a-8360-c84e95ebaa7d","html_url":"https://github.com/Shopify/shopify_python_api","commit_stats":{"total_commits":596,"total_committers":104,"mean_commits":5.730769230769231,"dds":0.8221476510067114,"last_synced_commit":"20c9be99f0dc424373c041a0141c4f0bda6aca4d"},"previous_names":[],"tags_count":83,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fshopify_python_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fshopify_python_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fshopify_python_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Fshopify_python_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shopify","download_url":"https://codeload.github.com/Shopify/shopify_python_api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246869617,"owners_count":20847161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:00:36.061Z","updated_at":"2025-04-02T18:30:38.228Z","avatar_url":"https://github.com/Shopify.png","language":"Python","readme":"# Shopify API\n\n[![Build Status](https://github.com/Shopify/shopify_python_api/workflows/CI/badge.svg)](https://github.com/Shopify/shopify_python_api/actions)\n[![PyPI version](https://badge.fury.io/py/ShopifyAPI.svg)](https://badge.fury.io/py/ShopifyAPI)\n![Supported Python Versions](https://img.shields.io/badge/python-3.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-brightgreen)\n[![codecov](https://codecov.io/gh/Shopify/shopify_python_api/branch/main/graph/badge.svg?token=pNTx0TARUx)](https://codecov.io/gh/Shopify/shopify_python_api)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Shopify/shopify_python_api/blob/main/LICENSE)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)](https://github.com/pre-commit/pre-commit)\n\nThe [Shopify Admin API](https://shopify.dev/docs/admin-api) Python Library\n\n## Usage\n\n### Requirements\nYou should be signed up as a partner on the [Shopify Partners Dashboard](https://www.shopify.com/partners) so that you can create and manage shopify applications.\n\n### Installation\n\nTo easily install or upgrade to the latest release, use [pip](http://www.pip-installer.org/).\n\n```shell\npip install --upgrade ShopifyAPI\n```\n\n### Table of Contents\n\n- [Usage](#usage)\n  - [Requirements](#requirements)\n  - [Installation](#installation)\n  - [Table of Contents](#table-of-contents)\n  - [Getting Started](#getting-started)\n    - [Public and Custom Apps](#public-and-custom-apps)\n    - [Private Apps](#private-apps)\n      - [With full session](#with-full-session)\n      - [With temporary session](#with-temporary-session)\n  - [Billing](#billing)\n  - [Advanced Usage](#advanced-usage)\n  - [Prefix options](#prefix-options)\n  - [Console](#console)\n  - [GraphQL](#graphql)\n- [Using Development Version](#using-development-version)\n    - [Building and installing dev version](#building-and-installing-dev-version)\n    - [Running Tests](#running-tests)\n- [Relative Cursor Pagination](#relative-cursor-pagination)\n- [Set up pre-commit locally \\[OPTIONAL\\]](#set-up-pre-commit-locally-optional)\n- [Limitations](#limitations)\n- [Additional Resources](#additional-resources)\n  - [Sample apps built using this library](#sample-apps-built-using-this-library)\n\n\n### Getting Started\n#### Public and Custom Apps\n\n1. First create a new application in the [Partners Dashboard](https://www.shopify.com/partners), and retrieve your API Key and API Secret Key.\n1. We then need to supply these keys to the Shopify Session Class so that it knows how to authenticate.\n\n   ```python\n   import shopify\n\n   shopify.Session.setup(api_key=API_KEY, secret=API_SECRET)\n   ```\n1.  In order to access a shop's data, apps need an access token from that specific shop. We need to authenticate with that shop using OAuth, which we can start in the following way:\n\n    ```python\n    shop_url = \"SHOP_NAME.myshopify.com\"\n    api_version = '2024-07'\n    state = binascii.b2a_hex(os.urandom(15)).decode(\"utf-8\")\n    redirect_uri = \"http://myapp.com/auth/shopify/callback\"\n    # `scope` should be omitted if provided by app's TOML\n    scopes = ['read_products', 'read_orders']\n\n    newSession = shopify.Session(shop_url, api_version)\n    # `scope` should be omitted if provided by app's TOML\n    auth_url = newSession.create_permission_url(redirect_uri, scopes, state)\n    # redirect to auth_url\n    ```\n\n1. Once the merchant accepts, the shop redirects the owner to the `redirect_uri` of your application with a parameter named 'code'. This is a temporary token that the app can exchange for a permanent access token. You should compare the state you provided above with the one you received back to ensure the request is correct. Now we can exchange the code for an access_token when you get the request from shopify in your callback handler:\n\n    ```python\n    session = shopify.Session(shop_url, api_version)\n    access_token = session.request_token(request_params) # request_token will validate hmac and timing attacks\n    # you should save the access token now for future use.\n    ```\n\n1.  Now you're ready to make authorized API requests to your shop!:\n\n    ```python\n    session = shopify.Session(shop_url, api_version, access_token)\n    shopify.ShopifyResource.activate_session(session)\n\n    # Note: REST API examples will be deprecated in 2025\n    shop = shopify.Shop.current()  # Get the current shop\n    product = shopify.Product.find(179761209)  # Get a specific product\n\n    # GraphQL API example\n    shopify.GraphQL().execute(\"{ shop { name id } }\")\n    ```\n\n    Alternatively, you can use temp to initialize a Session and execute a command:\n\n     ```python\n     with shopify.Session.temp(shop_url, api_version, token):\n        product = shopify.Product.find()\n     ```\n\n1.  It is best practice to clear your session when you're done. A temporary session does this automatically:\n\n     ```python\n     shopify.ShopifyResource.clear_session()\n     ```\n\n#### Private Apps\nPrivate apps are a bit quicker to use because OAuth is not needed. You can create the private app in the Shopify Merchant Admin. You can use the Private App password as your `access_token`:\n\n##### With full session\n```python\nsession = shopify.Session(shop_url, api_version, private_app_password)\nshopify.ShopifyResource.activate_session(session)\n# ...\nshopify.ShopifyResource.clear_session()\n```\n\n##### With temporary session\n\n```python\nwith shopify.Session.temp(shop_url, api_version, private_app_password):\n    shopify.GraphQL().execute(\"{ shop { name id } }\")\n```\n\n### Billing\n_Note: Your application must be public to test the billing process. To test on a development store use the `'test': True` flag_\n\n1.  Create charge after session has been activated\n    ```python\n    application_charge = shopify.ApplicationCharge.create({\n        'name': 'My public app',\n        'price': 123,\n        'test': True,\n        'return_url': 'https://domain.com/approve'\n    })\n    # Redirect user to application_charge.confirmation_url so they can approve the charge\n    ```\n1.  After approving the charge, the user is redirected to `return_url` with `charge_id` parameter (_Note: This action is no longer necessary if the charge is created with [API version 2021-01 or later](https://shopify.dev/changelog/auto-activation-of-charges-and-subscriptions)_)\n    ```python\n    charge = shopify.ApplicationCharge.find(charge_id)\n    shopify.ApplicationCharge.activate(charge)\n    ```\n1.  Check that `activated_charge` status is `active`\n    ```python\n    activated_charge = shopify.ApplicationCharge.find(charge_id)\n    has_been_billed = activated_charge.status == 'active'\n    ```\n\n### Advanced Usage\n\n\u003e **⚠️ Note**: As of October 1, 2024, the REST Admin API is legacy:\n\u003e - Public apps must migrate to GraphQL by February 2025\n\u003e - Custom apps must migrate to GraphQL by April 2025\n\u003e\n\u003e For migration guidance, see [Shopify's migration guide](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model)\n\nIt is recommended to have at least a basic grasp on the principles of the [pyactiveresource](https://github.com/Shopify/pyactiveresource) library, which is a port of rails/ActiveResource to Python and upon which this package relies heavily.\n\nInstances of `pyactiveresource` resources map to RESTful resources in the Shopify API.\n\n`pyactiveresource` exposes life cycle methods for creating, finding, updating, and deleting resources which are equivalent to the `POST`, `GET`, `PUT`, and `DELETE` HTTP verbs.\n\n```python\n# Note: REST API examples will be deprecated in 2025\nproduct = shopify.Product()\nproduct.title = \"Shopify Logo T-Shirt\"\nproduct.id                          # =\u003e 292082188312\nproduct.save()                      # =\u003e True\nshopify.Product.exists(product.id)  # =\u003e True\nproduct = shopify.Product.find(292082188312)\n# Resource holding our newly created Product object\n# Inspect attributes with product.attributes\nproduct.price = 19.99\nproduct.save()                      # =\u003e True\nproduct.destroy()\n# Delete the resource from the remote server (i.e. Shopify)\n```\n\nHere is another example to retrieve a list of open orders using certain parameters:\n\n```python\nnew_orders = shopify.Order.find(status=\"open\", limit=\"50\")\n```\n\n### Prefix options\n\nSome resources such as `Fulfillment` are prefixed by a parent resource in the Shopify API (e.g. `orders/450789469/fulfillments/255858046`). In order to interact with these resources, you must specify the identifier of the parent resource in your request.\n\n```python\n# Note: This REST API example will be deprecated in the future\nshopify.Fulfillment.find(255858046, order_id=450789469)\n```\n\n### Console\nThis package also includes the `shopify_api.py` script to make it easy to open an interactive console to use the API with a shop.\n1.  Obtain a private API key and password to use with your shop (step 2 in \"Getting Started\")\n1.  Save your default credentials: `shopify_api.py add yourshopname`\n1.  Start the console for the connection: `shopify_api.py console`\n1.  To see the full list of commands, type: `shopify_api.py help`\n\n### GraphQL\n\nThis library also supports Shopify's new [GraphQL API](https://help.shopify.com/en/api/graphql-admin-api). The authentication process is identical. Once your session is activated, simply construct a new graphql client and use `execute` to execute the query.\n\n\u003e **Note**: Shopify recommends using GraphQL API for new development as REST API will be deprecated.\n\u003e See [Migration Guide](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model) for more details.\n\n```python\nresult = shopify.GraphQL().execute('{ shop { name id } }')\n```\n\nYou can perform more complex operations using the `variables` and `operation_name` parameters of `execute`.\n\nFor example, this GraphQL document uses a fragment to construct two named queries - one for a single order, and one for multiple orders:\n\n```graphql\n    # ./order_queries.graphql\n\n    fragment OrderInfo on Order {\n        id\n        name\n        createdAt\n    }\n\n    query GetOneOrder($order_id: ID!){\n        node(id: $order_id){\n            ...OrderInfo\n        }\n    }\n\n    query GetManyOrders($order_ids: [ID]!){\n        nodes(ids: $order_ids){\n           ...OrderInfo\n        }\n    }\n```\n\nNow you can choose which operation to execute:\n\n```python\n# Load the document with both queries\ndocument = Path(\"./order_queries.graphql\").read_text()\n\n# Specify the named operation to execute, and the parameters for the query\nresult = shopify.GraphQL().execute(\n    query=document,\n    variables={\"order_id\": \"gid://shopify/Order/12345\"},\n    operation_name=\"GetOneOrder\",\n)\n```\n\n## Using Development Version\n\n#### Building and installing dev version\n```shell\npython setup.py sdist\npip install --upgrade dist/ShopifyAPI-*.tar.gz\n```\n\n**Note** Use the `bin/shopify_api.py` script when running from the source tree. It will add the lib directory to start of sys.path, so the installed version won't be used.\n\n#### Running Tests\n```shell\npip install setuptools --upgrade\npython setup.py test\n```\n\n## Relative Cursor Pagination\nCursor based pagination support has been added in 6.0.0.\n\n```python\nimport shopify\n\npage1 = shopify.Product.find()\nif page1.has_next_page():\n  page2 = page1.next_page()\n\n# to persist across requests you can use next_page_url and previous_page_url\nnext_url = page1.next_page_url\npage2 = shopify.Product.find(from_=next_url)\n```\n\n## Set up pre-commit locally [OPTIONAL]\n[Pre-commit](https://pre-commit.com/) is set up as a GitHub action that runs on pull requests and pushes to the `main` branch. If you want to run pre-commit locally, install it and set up the git hook scripts\n```shell\npip install -r requirements.txt\npre-commit install\n```\n\n## Limitations\n\nCurrently there is no support for:\n\n* asynchronous requests\n* persistent connections\n\n## Additional Resources\n* [Partners Dashboard](https://partners.shopify.com)\n* [developers.shopify.com](https://developers.shopify.com)\n* [Shopify.dev](https://shopify.dev)\n* [Ask questions on the Shopify forums](http://ecommerce.shopify.com/c/shopify-apis-and-technology)\n\n### Sample apps built using this library\n* [Sample Django app](https://github.com/shopify/sample-django-app)\n","funding_links":[],"categories":["Python","Libraries","\u003ca name=\"Python\"\u003e\u003c/a\u003ePython","库"],"sub_categories":["Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2Fshopify_python_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShopify%2Fshopify_python_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2Fshopify_python_api/lists"}