From 81252346c63cb51d25ebdd1e0d44c85b68aa7479 Mon Sep 17 00:00:00 2001 From: Elizabeth Kenyon Date: Mon, 8 Apr 2024 13:43:41 -0500 Subject: [PATCH 01/20] Add support for April24 API version --- CHANGELOG | 1 + shopify/api_version.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c7309ca8..0a0c47e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ == Unreleased - Remove `cgi` import to avoid triggering a `DeprecationWarning` on Python 3.11. +- Update API version with 2024-04 release. == Version 12.4.0 diff --git a/shopify/api_version.py b/shopify/api_version.py index ba137d57..a0a1531e 100644 --- a/shopify/api_version.py +++ b/shopify/api_version.py @@ -37,6 +37,7 @@ def define_known_versions(cls): cls.define_version(Release("2023-07")) cls.define_version(Release("2023-10")) cls.define_version(Release("2024-01")) + cls.define_version(Release("2024-04")) @classmethod def clear_defined_versions(cls): From 74373bfc93ddc2539b2bd442f5ea2876ec5345ec Mon Sep 17 00:00:00 2001 From: Elizabeth Kenyon Date: Mon, 8 Apr 2024 14:58:51 -0500 Subject: [PATCH 02/20] Update codecov action Testing to see if this resolves the pipeline failures --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a44a442..58a2a8cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - name: Run Tests run: python -m pytest -v - name: upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: name: codecov-umbrella fail_ci_if_error: true From 8029a749cafeac18a95fe5546867a369a4c719c8 Mon Sep 17 00:00:00 2001 From: Elizabeth Kenyon Date: Tue, 9 Apr 2024 09:53:00 -0500 Subject: [PATCH 03/20] turn off CI failure for codecov We are getting increasing failures because of this task --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58a2a8cb..e7ec6d36 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - name: Run Tests run: python -m pytest -v - name: upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v1 with: name: codecov-umbrella - fail_ci_if_error: true + fail_ci_if_error: false From 65f5ce2a6f30d49995c8af6ff52796f5a0ffe9cc Mon Sep 17 00:00:00 2001 From: Elizabeth Kenyon Date: Tue, 9 Apr 2024 10:28:01 -0500 Subject: [PATCH 04/20] Preparing for release --- CHANGELOG | 3 ++- shopify/version.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0a0c47e4..c4462f6e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ == Unreleased +== Version 12.5.0 - Remove `cgi` import to avoid triggering a `DeprecationWarning` on Python 3.11. -- Update API version with 2024-04 release. +- Update API version with 2024-04 release.([710](https://github.com/Shopify/shopify_python_api/pull/710)) == Version 12.4.0 diff --git a/shopify/version.py b/shopify/version.py index 7c16e69e..3958d1de 100644 --- a/shopify/version.py +++ b/shopify/version.py @@ -1 +1 @@ -VERSION = "12.4.0" +VERSION = "12.5.0" From 2ef7f2219fe06260e7af4d7ca531f9a8f9f3db3d Mon Sep 17 00:00:00 2001 From: bvoelsch Date: Thu, 11 Jan 2024 15:08:14 -0700 Subject: [PATCH 05/20] Update __init__.py Add FulfillmentV2 method to init --- shopify/resources/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify/resources/__init__.py b/shopify/resources/__init__.py index 16220739..0d420b38 100644 --- a/shopify/resources/__init__.py +++ b/shopify/resources/__init__.py @@ -38,7 +38,7 @@ from .page import Page from .country import Country from .refund import Refund -from .fulfillment import Fulfillment, FulfillmentOrders +from .fulfillment import Fulfillment, FulfillmentOrders, FulfillmentV2 from .fulfillment_event import FulfillmentEvent from .fulfillment_service import FulfillmentService from .carrier_service import CarrierService From a9277784740ef03c2789c868dfb957b3e670725a Mon Sep 17 00:00:00 2001 From: Matteo Depalo Date: Wed, 22 May 2024 15:43:20 +0100 Subject: [PATCH 06/20] Rename master to main --- .github/workflows/pre-commit.yml | 2 +- .github/workflows/stale.yml | 2 +- README.md | 34 ++++++++++++++++++++------------ RELEASING | 2 +- SECURITY.md | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 048bc5a2..f92848d7 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -3,7 +3,7 @@ name: pre-commit on: pull_request: push: - branches: [master] + branches: [main] jobs: pre-commit: diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index cd1f94c0..2d0a3ec7 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -22,7 +22,7 @@ jobs: This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority. - If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the [CONTRIBUTING.md](https://github.com/Shopify/shopify_python_api/blob/master/CONTRIBUTING.md) file for guidelines + If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the [CONTRIBUTING.md](https://github.com/Shopify/shopify_python_api/blob/main/CONTRIBUTING.md) file for guidelines Thank you! days-before-pr-stale: -1 diff --git a/README.md b/README.md index 7dc84ed5..d8519b1b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Build Status](https://github.com/Shopify/shopify_python_api/workflows/CI/badge.svg)](https://github.com/Shopify/shopify_python_api/actions) [![PyPI version](https://badge.fury.io/py/ShopifyAPI.svg)](https://badge.fury.io/py/ShopifyAPI) -[![codecov](https://codecov.io/gh/Shopify/shopify_python_api/branch/master/graph/badge.svg?token=pNTx0TARUx)](https://codecov.io/gh/Shopify/shopify_python_api) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Shopify/shopify_python_api/blob/master/LICENSE) +[![codecov](https://codecov.io/gh/Shopify/shopify_python_api/branch/main/graph/badge.svg?token=pNTx0TARUx)](https://codecov.io/gh/Shopify/shopify_python_api) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Shopify/shopify_python_api/blob/main/LICENSE) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) The [Shopify Admin API](https://shopify.dev/docs/admin-api) Python Library @@ -23,20 +23,28 @@ pip install --upgrade ShopifyAPI ### Table of Contents -- [Getting Started](#getting-started) - - [Public and Custom Apps](#public-and-custom-apps) - - [Private Apps](#private-apps) -- [Billing](#billing) -- [Session Tokens](docs/session-tokens.md) -- [Handling Access Scope Operations](docs/api-access.md) -- [Advanced Usage](#advanced-usage) -- [Prefix Options](#prefix-options) -- [Console](#console) -- [GraphQL](#graphql) +- [Usage](#usage) + - [Requirements](#requirements) + - [Installation](#installation) + - [Table of Contents](#table-of-contents) + - [Getting Started](#getting-started) + - [Public and Custom Apps](#public-and-custom-apps) + - [Private Apps](#private-apps) + - [With full session](#with-full-session) + - [With temporary session](#with-temporary-session) + - [Billing](#billing) + - [Advanced Usage](#advanced-usage) + - [Prefix options](#prefix-options) + - [Console](#console) + - [GraphQL](#graphql) - [Using Development Version](#using-development-version) + - [Building and installing dev version](#building-and-installing-dev-version) + - [Running Tests](#running-tests) - [Relative Cursor Pagination](#relative-cursor-pagination) +- [Set up pre-commit locally \[OPTIONAL\]](#set-up-pre-commit-locally-optional) - [Limitations](#limitations) - [Additional Resources](#additional-resources) + - [Sample apps built using this library](#sample-apps-built-using-this-library) ### Getting Started @@ -263,7 +271,7 @@ page2 = shopify.Product.find(from_=next_url) ``` ## Set up pre-commit locally [OPTIONAL] -[Pre-commit](https://pre-commit.com/) is set up as a GitHub action that runs on pull requests and pushes to the `master` branch. If you want to run pre-commit locally, install it and set up the git hook scripts +[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 ```shell pip install -r requirements.txt pre-commit install diff --git a/RELEASING b/RELEASING index f84fa314..a15667a0 100644 --- a/RELEASING +++ b/RELEASING @@ -15,6 +15,6 @@ Releasing shopify_python_api git tag -m "Release X.Y.Z" vX.Y.Z 7. Push the changes to github - git push --tags origin master + git push --tags origin main 8. Shipit! diff --git a/SECURITY.md b/SECURITY.md index 2d13b5e1..2a0e9c48 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,7 +4,7 @@ ### New features -New features will only be added to the master branch and will not be made available in point releases. +New features will only be added to the main branch and will not be made available in point releases. ### Bug fixes From 741555f072d41309d1233fe07e08977715498aa6 Mon Sep 17 00:00:00 2001 From: Paulo Margarido <64600052+paulomarg@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:19:41 -0400 Subject: [PATCH 07/20] Add support for 2024-07 API version --- .github/workflows/build.yml | 4 ++-- CHANGELOG | 3 +++ README.md | 2 +- shopify/api_version.py | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7ec6d36..c0cd5ab9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: name: Python ${{ matrix.version }} strategy: matrix: - version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout @@ -18,7 +18,7 @@ jobs: - name: Install Dependencies run: | python -m pip install --upgrade pip - pip install pytest mock pytest-cov + pip install pytest mock pytest-cov setuptools python setup.py install pytest --cov=./ --cov-report=xml - name: Run Tests diff --git a/CHANGELOG b/CHANGELOG index c4462f6e..24fb1752 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ == Unreleased +- Update API version with 2024-07 release ([#](https://github.com/Shopify/shopify_python_api/pull/)) + == Version 12.5.0 + - Remove `cgi` import to avoid triggering a `DeprecationWarning` on Python 3.11. - Update API version with 2024-04 release.([710](https://github.com/Shopify/shopify_python_api/pull/710)) diff --git a/README.md b/README.md index d8519b1b..066bd343 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ pip install --upgrade ShopifyAPI ```python shop_url = "SHOP_NAME.myshopify.com" - api_version = '2024-01' + api_version = '2024-07' state = binascii.b2a_hex(os.urandom(15)).decode("utf-8") redirect_uri = "http://myapp.com/auth/shopify/callback" scopes = ['read_products', 'read_orders'] diff --git a/shopify/api_version.py b/shopify/api_version.py index a0a1531e..22df6052 100644 --- a/shopify/api_version.py +++ b/shopify/api_version.py @@ -38,6 +38,7 @@ def define_known_versions(cls): cls.define_version(Release("2023-10")) cls.define_version(Release("2024-01")) cls.define_version(Release("2024-04")) + cls.define_version(Release("2024-07")) @classmethod def clear_defined_versions(cls): From 05d59c88c82994dfebf683c35acdebea9a8fab7b Mon Sep 17 00:00:00 2001 From: Paulo Margarido <64600052+paulomarg@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:38:26 -0400 Subject: [PATCH 08/20] Release v12.6.0 --- CHANGELOG | 4 +++- shopify/version.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 24fb1752..cd636df3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ == Unreleased -- Update API version with 2024-07 release ([#](https://github.com/Shopify/shopify_python_api/pull/)) +== Version 12.6.0 + +- Update API version with 2024-07 release ([#723](https://github.com/Shopify/shopify_python_api/pull/723)) == Version 12.5.0 diff --git a/shopify/version.py b/shopify/version.py index 3958d1de..7293b298 100644 --- a/shopify/version.py +++ b/shopify/version.py @@ -1 +1 @@ -VERSION = "12.5.0" +VERSION = "12.6.0" From f7fe4c663c4d341fbbbed0b9691354ba288fa7ba Mon Sep 17 00:00:00 2001 From: James Gilmore Date: Tue, 9 Jul 2024 10:53:52 +0100 Subject: [PATCH 09/20] Add support for building the package in Python 3.12 As discussed in the [issue](https://github.com/Shopify/shopify_python_api/issues/725) there is an issue when trying to install this package when using Python 3.12. The issue is caused by [PEP-632](https://peps.python.org/pep-0632/) removing `distutils` from the built-in libraries this version of python is shipped with. In versions 6.0.0 and lower of PyYaml, this causes the build the fail. As mentioned in their [issue](https://github.com/yaml/pyyaml/issues/756) using v6.0.1 or later will resolve this issue. So updating our `setup.py` install_requires dependency specifications to reflect this. While I'm here, also update the classifiers to include support for PY3.12 and show this more clearly on the README of the repo. --- README.md | 1 + setup.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 066bd343..a8fa6d74 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://github.com/Shopify/shopify_python_api/workflows/CI/badge.svg)](https://github.com/Shopify/shopify_python_api/actions) [![PyPI version](https://badge.fury.io/py/ShopifyAPI.svg)](https://badge.fury.io/py/ShopifyAPI) +![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) [![codecov](https://codecov.io/gh/Shopify/shopify_python_api/branch/main/graph/badge.svg?token=pNTx0TARUx)](https://codecov.io/gh/Shopify/shopify_python_api) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Shopify/shopify_python_api/blob/main/LICENSE) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) diff --git a/setup.py b/setup.py index dae5a810..eb23ab08 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,8 @@ install_requires=[ "pyactiveresource>=2.2.2", "PyJWT >= 2.0.0", - "PyYAML", + "PyYAML>=6.0.1; python_version>='3.12'", + "PyYAML; python_version<'3.12'", "six", ], test_suite="test", @@ -44,6 +45,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", From fdc155e64bcc86504834b1a01d0871232b7c5e08 Mon Sep 17 00:00:00 2001 From: Elizabeth Kenyon Date: Tue, 24 Sep 2024 13:36:25 -0500 Subject: [PATCH 10/20] Make API version more flexible Allow the use of API versions that are not previsouly defined --- CHANGELOG | 1 + shopify/api_version.py | 4 ++++ test/api_version_test.py | 14 ++++++++++++++ test/session_test.py | 13 +++++++++++++ 4 files changed, 32 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index cd636df3..5a5ed5db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ == Unreleased +- Remove requirement to use a predefined API version. Now you can use any valid API version string. ([#737](https://github.com/Shopify/shopify_python_api/pull/737)) == Version 12.6.0 diff --git a/shopify/api_version.py b/shopify/api_version.py index 22df6052..32276668 100644 --- a/shopify/api_version.py +++ b/shopify/api_version.py @@ -17,6 +17,9 @@ def coerce_to_version(cls, version): try: return cls.versions[version] except KeyError: + # Dynamically create a new Release object if version string is not found + if Release.FORMAT.match(version): + return Release(version) raise VersionNotFoundError @classmethod @@ -39,6 +42,7 @@ def define_known_versions(cls): cls.define_version(Release("2024-01")) cls.define_version(Release("2024-04")) cls.define_version(Release("2024-07")) + cls.define_version(Release("2024-10")) @classmethod def clear_defined_versions(cls): diff --git a/test/api_version_test.py b/test/api_version_test.py index 3089daee..9dce8cb2 100644 --- a/test/api_version_test.py +++ b/test/api_version_test.py @@ -29,6 +29,20 @@ def test_coerce_to_version_raises_with_string_that_does_not_match_known_version( with self.assertRaises(shopify.VersionNotFoundError): shopify.ApiVersion.coerce_to_version("crazy-name") + def test_coerce_to_version_creates_new_release_on_the_fly(self): + new_version = "2025-01" + coerced_version = shopify.ApiVersion.coerce_to_version(new_version) + + self.assertIsInstance(coerced_version, shopify.Release) + self.assertEqual(coerced_version.name, new_version) + self.assertEqual( + coerced_version.api_path("https://test.myshopify.com"), + f"https://test.myshopify.com/admin/api/{new_version}", + ) + + # Verify that the new version is not added to the known versions + self.assertNotIn(new_version, shopify.ApiVersion.versions) + class ReleaseTest(TestCase): def test_raises_if_format_invalid(self): diff --git a/test/session_test.py b/test/session_test.py index 806d551b..d7cd5c3d 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -288,3 +288,16 @@ def normalize_url(self, url): scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url) query = "&".join(sorted(query.split("&"))) return urllib.parse.urlunsplit((scheme, netloc, path, query, fragment)) + + def test_session_with_coerced_version(self): + future_version = "2030-01" + session = shopify.Session("test.myshopify.com", future_version, "token") + self.assertEqual(session.api_version.name, future_version) + self.assertEqual( + session.api_version.api_path("https://test.myshopify.com"), + f"https://test.myshopify.com/admin/api/{future_version}", + ) + + def test_session_with_invalid_version(self): + with self.assertRaises(shopify.VersionNotFoundError): + shopify.Session("test.myshopify.com", "invalid-version", "token") From 7229004441645b1bc0a4c848cc1a6593fc9d6281 Mon Sep 17 00:00:00 2001 From: Matteo Depalo Date: Wed, 30 Oct 2024 10:46:27 +0000 Subject: [PATCH 11/20] Release v12.7.0 --- CHANGELOG | 3 +++ shopify/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5a5ed5db..50cae06e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ == Unreleased + +== Version 12.7.0 + - Remove requirement to use a predefined API version. Now you can use any valid API version string. ([#737](https://github.com/Shopify/shopify_python_api/pull/737)) == Version 12.6.0 diff --git a/shopify/version.py b/shopify/version.py index 7293b298..126c3ab4 100644 --- a/shopify/version.py +++ b/shopify/version.py @@ -1 +1 @@ -VERSION = "12.6.0" +VERSION = "12.7.0" From 9451fe5f45c6d809787384e9ceaa294fec1b66c6 Mon Sep 17 00:00:00 2001 From: "yuichi.nasukawa" Date: Wed, 8 Jan 2025 22:01:30 +0900 Subject: [PATCH 12/20] Add REST API deprecation notice to README --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8fa6d74..6226bcb1 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,11 @@ pip install --upgrade ShopifyAPI session = shopify.Session(shop_url, api_version, access_token) shopify.ShopifyResource.activate_session(session) - shop = shopify.Shop.current() # Get the current shop - product = shopify.Product.find(179761209) # Get a specific product + # Note: REST API examples will be deprecated in 2025 + shop = shopify.Shop.current() # Get the current shop + product = shopify.Product.find(179761209) # Get a specific product - # execute a graphQL call + # GraphQL API example shopify.GraphQL().execute("{ shop { name id } }") ``` @@ -150,6 +151,13 @@ _Note: Your application must be public to test the billing process. To test on a ``` ### Advanced Usage + +> **⚠️ Note**: As of October 1, 2024, the REST Admin API is legacy: +> - Public apps must migrate to GraphQL by February 2025 +> - Custom apps must migrate to GraphQL by April 2025 +> +> For migration guidance, see [Shopify's migration guide](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model) + It 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. Instances of `pyactiveresource` resources map to RESTful resources in the Shopify API. @@ -157,6 +165,7 @@ Instances of `pyactiveresource` resources map to RESTful resources in the Shopif `pyactiveresource` exposes life cycle methods for creating, finding, updating, and deleting resources which are equivalent to the `POST`, `GET`, `PUT`, and `DELETE` HTTP verbs. ```python +# Note: REST API examples will be deprecated in 2025 product = shopify.Product() product.title = "Shopify Logo T-Shirt" product.id # => 292082188312 @@ -182,6 +191,7 @@ new_orders = shopify.Order.find(status="open", limit="50") Some 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. ```python +# Note: This REST API example will be deprecated in the future shopify.Fulfillment.find(255858046, order_id=450789469) ``` @@ -196,6 +206,9 @@ This package also includes the `shopify_api.py` script to make it easy to open a This 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. +> **Note**: Shopify recommends using GraphQL API for new development as REST API will be deprecated. +> See [Migration Guide](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model) for more details. + ```python result = shopify.GraphQL().execute('{ shop { name id } }') ``` From 024d94691ed889d047704d2f1615f40a03cc02ac Mon Sep 17 00:00:00 2001 From: Tyler J Date: Sat, 11 Jan 2025 13:31:05 -0500 Subject: [PATCH 13/20] Refactor `create_permission_url` to handle optional `scope`. Modified `create_permission_url` to make `scope` optional, allowing it to be omitted when specified in the app's configuration (TOML). Updated the README to reflect this change and clarify usage. This improves flexibility and simplifies configuration management. --- README.md | 4 +++- shopify/session.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a8fa6d74..0b680d07 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,12 @@ pip install --upgrade ShopifyAPI api_version = '2024-07' state = binascii.b2a_hex(os.urandom(15)).decode("utf-8") redirect_uri = "http://myapp.com/auth/shopify/callback" + # `scope` should be omitted if provided by app's TOML scopes = ['read_products', 'read_orders'] newSession = shopify.Session(shop_url, api_version) - auth_url = newSession.create_permission_url(scopes, redirect_uri, state) + # `scope` should be omitted if provided by app's TOML + auth_url = newSession.create_permission_url(redirect_uri, scopes, state) # redirect to auth_url ``` diff --git a/shopify/session.py b/shopify/session.py index 39ce5f7b..52dc83f4 100644 --- a/shopify/session.py +++ b/shopify/session.py @@ -53,10 +53,11 @@ def __init__(self, shop_url, version=None, token=None, access_scopes=None): self.access_scopes = access_scopes return - def create_permission_url(self, scope, redirect_uri, state=None): - query_params = dict(client_id=self.api_key, scope=",".join(scope), redirect_uri=redirect_uri) - if state: - query_params["state"] = state + def create_permission_url(self, redirect_uri, scope=None, state=None): + query_params = dict(client_id=self.api_key, redirect_uri=redirect_uri) + # `scope` should be omitted if provided by app's TOML + if scope: query_params["scope"] = ",".join(scope) + if state: query_params["state"] = state return "https://%s/admin/oauth/authorize?%s" % (self.url, urllib.parse.urlencode(query_params)) def request_token(self, params): From cdaa10d2d6a82d44652468d0d78aba537df08baa Mon Sep 17 00:00:00 2001 From: "yuichi.nasukawa" Date: Sun, 12 Jan 2025 08:40:56 +0900 Subject: [PATCH 14/20] chore: upgrade pre-commit dependencies --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43267923..f3500257 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,15 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/PyCQA/pylint - rev: v2.15.8 + rev: v3.3.3 hooks: - id: pylint From 7b044441d59fe9087abc02554cbf267fb9a6d923 Mon Sep 17 00:00:00 2001 From: "yuichi.nasukawa" Date: Sun, 12 Jan 2025 08:44:30 +0900 Subject: [PATCH 15/20] fix: resolve new pylint warnings - Fix warnings introduced by pylint v3.3.3 upgrade --- scripts/shopify_api.py | 2 +- shopify/api_access.py | 1 - shopify/mixins.py | 2 +- shopify/session.py | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/shopify_api.py b/scripts/shopify_api.py index 5dfab93a..bab35f15 100755 --- a/scripts/shopify_api.py +++ b/scripts/shopify_api.py @@ -128,7 +128,7 @@ def add(cls, connection): if os.path.exists(filename): raise ConfigFileError("There is already a config file at " + filename) else: - config = dict(protocol="https") + config = {"protocol": "https"} domain = input("Domain? (leave blank for %s.myshopify.com) " % (connection)) if not domain.strip(): domain = "%s.myshopify.com" % (connection) diff --git a/shopify/api_access.py b/shopify/api_access.py index d5ffbe35..19b80671 100644 --- a/shopify/api_access.py +++ b/shopify/api_access.py @@ -14,7 +14,6 @@ class ApiAccessError(Exception): class ApiAccess: - SCOPE_DELIMITER = "," SCOPE_RE = re.compile(r"\A(?Punauthenticated_)?(write|read)_(?P.*)\Z") IMPLIED_SCOPE_RE = re.compile(r"\A(?Punauthenticated_)?write_(?P.*)\Z") diff --git a/shopify/mixins.py b/shopify/mixins.py index 54496dbf..5a13ca3a 100644 --- a/shopify/mixins.py +++ b/shopify/mixins.py @@ -24,7 +24,7 @@ def add_metafield(self, metafield): if self.is_new(): raise ValueError("You can only add metafields to a resource that has been saved") - metafield._prefix_options = dict(resource=self.__class__.plural, resource_id=self.id) + metafield._prefix_options = {"resource": self.__class__.plural, "resource_id": self.id} metafield.save() return metafield diff --git a/shopify/session.py b/shopify/session.py index 39ce5f7b..c3ec6d4b 100644 --- a/shopify/session.py +++ b/shopify/session.py @@ -54,7 +54,7 @@ def __init__(self, shop_url, version=None, token=None, access_scopes=None): return def create_permission_url(self, scope, redirect_uri, state=None): - query_params = dict(client_id=self.api_key, scope=",".join(scope), redirect_uri=redirect_uri) + query_params = {"client_id": self.api_key, "scope": ",".join(scope), "redirect_uri": redirect_uri} if state: query_params["state"] = state return "https://%s/admin/oauth/authorize?%s" % (self.url, urllib.parse.urlencode(query_params)) @@ -69,7 +69,7 @@ def request_token(self, params): code = params["code"] url = "https://%s/admin/oauth/access_token?" % self.url - query_params = dict(client_id=self.api_key, client_secret=self.secret, code=code) + query_params = {"client_id": self.api_key, "client_secret": self.secret, "code": code} request = urllib.request.Request(url, urllib.parse.urlencode(query_params).encode("utf-8")) response = urllib.request.urlopen(request) From ceada2433b004365b7d9f74669b9c1067e299ccb Mon Sep 17 00:00:00 2001 From: Tyler J Date: Sun, 12 Jan 2025 11:33:31 -0500 Subject: [PATCH 16/20] Update to version 12.7.1 and update the CHANGELOG. --- CHANGELOG | 2 ++ shopify/version.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 50cae06e..e9910c2e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ == Unreleased +- Remove requirement to provide scopes to Permission URL, as it should be omitted if defined with the TOML file. + == Version 12.7.0 - Remove requirement to use a predefined API version. Now you can use any valid API version string. ([#737](https://github.com/Shopify/shopify_python_api/pull/737)) diff --git a/shopify/version.py b/shopify/version.py index 126c3ab4..dfb0b4e4 100644 --- a/shopify/version.py +++ b/shopify/version.py @@ -1 +1 @@ -VERSION = "12.7.0" +VERSION = "12.7.1" From 07d6c47146e00c35bb39a83d86033f9b250623af Mon Sep 17 00:00:00 2001 From: Tyler J Date: Sun, 12 Jan 2025 11:48:02 -0500 Subject: [PATCH 17/20] Fix typo in method signature of create_permission_url Removed an unnecessary extra space in the method signature of `create_permission_url`. --- shopify/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify/session.py b/shopify/session.py index 52dc83f4..eec40517 100644 --- a/shopify/session.py +++ b/shopify/session.py @@ -53,7 +53,7 @@ def __init__(self, shop_url, version=None, token=None, access_scopes=None): self.access_scopes = access_scopes return - def create_permission_url(self, redirect_uri, scope=None, state=None): + def create_permission_url(self, redirect_uri, scope=None, state=None): query_params = dict(client_id=self.api_key, redirect_uri=redirect_uri) # `scope` should be omitted if provided by app's TOML if scope: query_params["scope"] = ",".join(scope) From adaf770a0b5a99ae791048967f39d89e13ea500f Mon Sep 17 00:00:00 2001 From: Tyler J Date: Fri, 17 Jan 2025 14:28:20 -0500 Subject: [PATCH 18/20] Update tests for `create_permission_url` method. Updated tests to improve clarity and consistency in naming and arguments. Modified `create_permission_url` calls to match new positional order for `redirect_uri` and `scope`. Enhanced assertion coverage for edge cases like empty scopes and added tests for state parameter handling. --- test/session_test.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/test/session_test.py b/test/session_test.py index d7cd5c3d..04d30748 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -86,51 +86,69 @@ def test_temp_works_without_currently_active_session(self): self.assertEqual("https://testshop.myshopify.com/admin/api/unstable", assigned_site) self.assertEqual("https://none/admin/api/unstable", shopify.ShopifyResource.site) - def test_create_permission_url_returns_correct_url_with_single_scope_and_redirect_uri(self): + def test_create_permission_url_returns_correct_url_with_redirect_uri(self): + shopify.Session.setup(api_key="My_test_key", secret="My test secret") + session = shopify.Session("http://localhost.myshopify.com", "unstable") + permission_url = session.create_permission_url("my_redirect_uri.com") + self.assertEqual( + "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com", + self.normalize_url(permission_url), + ) + + def test_create_permission_url_returns_correct_url_with_redirect_uri_and_single_scope(self): shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = ["write_products"] - permission_url = session.create_permission_url(scope, "my_redirect_uri.com") + permission_url = session.create_permission_url("my_redirect_uri.com", scope=scope) self.assertEqual( "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=write_products", self.normalize_url(permission_url), ) - def test_create_permission_url_returns_correct_url_with_dual_scope_and_redirect_uri(self): + def test_create_permission_url_returns_correct_url_with_redirect_uri_and_dual_scope(self): shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = ["write_products", "write_customers"] - permission_url = session.create_permission_url(scope, "my_redirect_uri.com") + permission_url = session.create_permission_url("my_redirect_uri.com", scope=scope) self.assertEqual( "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=write_products%2Cwrite_customers", self.normalize_url(permission_url), ) - def test_create_permission_url_returns_correct_url_with_no_scope_and_redirect_uri(self): + def test_create_permission_url_returns_correct_url_with_redirect_uri_and_empty_scope(self): shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = [] - permission_url = session.create_permission_url(scope, "my_redirect_uri.com") + permission_url = session.create_permission_url("my_redirect_uri.com", scope=scope) + self.assertEqual( + "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com", + self.normalize_url(permission_url), + ) + + def test_create_permission_url_returns_correct_url_with_redirect_uri_and_state(self): + shopify.Session.setup(api_key="My_test_key", secret="My test secret") + session = shopify.Session("http://localhost.myshopify.com", "unstable") + permission_url = session.create_permission_url("my_redirect_uri.com", state="mystate") self.assertEqual( - "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=", + "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&state=mystate", self.normalize_url(permission_url), ) - def test_create_permission_url_returns_correct_url_with_no_scope_and_redirect_uri_and_state(self): + def test_create_permission_url_returns_correct_url_with_redirect_uri_empty_scope_and_state(self): shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = [] - permission_url = session.create_permission_url(scope, "my_redirect_uri.com", state="mystate") + permission_url = session.create_permission_url("my_redirect_uri.com", scope=scope, state="mystate") self.assertEqual( - "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=&state=mystate", + "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&state=mystate", self.normalize_url(permission_url), ) - def test_create_permission_url_returns_correct_url_with_single_scope_and_redirect_uri_and_state(self): + def test_create_permission_url_returns_correct_url_with_redirect_uri_and_single_scope_and_state(self): shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = ["write_customers"] - permission_url = session.create_permission_url(scope, "my_redirect_uri.com", state="mystate") + permission_url = session.create_permission_url( "my_redirect_uri.com", scope=scope, state="mystate") self.assertEqual( "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=write_customers&state=mystate", self.normalize_url(permission_url), From 12e933ba9cadd2ba5b834fe5143cb70438e9e34b Mon Sep 17 00:00:00 2001 From: Tyler J Date: Mon, 20 Jan 2025 08:32:20 -0500 Subject: [PATCH 19/20] Fix linting errors Removes extra white space in parameters in session_test.py and changes conditional formatting in shopify/session.py. --- shopify/session.py | 8 +++++--- test/session_test.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/shopify/session.py b/shopify/session.py index eec40517..dcb41d41 100644 --- a/shopify/session.py +++ b/shopify/session.py @@ -54,10 +54,12 @@ def __init__(self, shop_url, version=None, token=None, access_scopes=None): return def create_permission_url(self, redirect_uri, scope=None, state=None): - query_params = dict(client_id=self.api_key, redirect_uri=redirect_uri) + query_params = {"client_id": self.api_key, "redirect_uri": redirect_uri} # `scope` should be omitted if provided by app's TOML - if scope: query_params["scope"] = ",".join(scope) - if state: query_params["state"] = state + if scope: + query_params["scope"] = ",".join(scope) + if state: + query_params["state"] = state return "https://%s/admin/oauth/authorize?%s" % (self.url, urllib.parse.urlencode(query_params)) def request_token(self, params): diff --git a/test/session_test.py b/test/session_test.py index 04d30748..8d73e293 100644 --- a/test/session_test.py +++ b/test/session_test.py @@ -148,7 +148,7 @@ def test_create_permission_url_returns_correct_url_with_redirect_uri_and_single_ shopify.Session.setup(api_key="My_test_key", secret="My test secret") session = shopify.Session("http://localhost.myshopify.com", "unstable") scope = ["write_customers"] - permission_url = session.create_permission_url( "my_redirect_uri.com", scope=scope, state="mystate") + permission_url = session.create_permission_url("my_redirect_uri.com", scope=scope, state="mystate") self.assertEqual( "https://localhost.myshopify.com/admin/oauth/authorize?client_id=My_test_key&redirect_uri=my_redirect_uri.com&scope=write_customers&state=mystate", self.normalize_url(permission_url), From 2f998c691bd15608603ef25e31238f6c22abc544 Mon Sep 17 00:00:00 2001 From: Tyler J Date: Mon, 20 Jan 2025 08:40:04 -0500 Subject: [PATCH 20/20] Fix linting errors Removes extra white space in parameters in session_test.py and changes conditional formatting in shopify/session.py. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8378880..cadda24e 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ _Note: Your application must be public to test the billing process. To test on a > **⚠️ Note**: As of October 1, 2024, the REST Admin API is legacy: > - Public apps must migrate to GraphQL by February 2025 > - Custom apps must migrate to GraphQL by April 2025 -> +> > For migration guidance, see [Shopify's migration guide](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model) It 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.