Skip to content

labd/commercetools-python-sdk

Repository files navigation

http://codecov.io/github/labd/commercetools-python-sdk/coverage.svg?branch=main Documentation Status

Python SDK for Commercetools

This is an unofficial Python SDK for the Commercetools platform. It only supports Python 3.6+ and uses type annotation for an improved development experience.

The API is generated using the commercetools api RAML file and uses marshmallow for the serialization and deserialization.

Installation

pip install commercetools

Example

from commercetools.platform import Client

client = Client(
    client_id="<your-client-id>",
    client_secret="<your-client-secret>",
    scope=["<scopes>"],
    url="https://api.europe-west1.gcp.commercetools.com",
    token_url="https://auth.europe-west1.gcp.commercetools.com",
)

product = (
    client
    .with_project_key("<your-project-key>")
    .products()
    .with_id("00633d11-c5bb-434e-b132-73f7e130b4e3")
    .get())
print(product)

The client can also be configured by setting the following environment variables:

export CTP_CLIENT_SECRET="<client secret>"
export CTP_CLIENT_ID="<client id>"
export CTP_AUTH_URL="https://api.europe-west1.gcp.commercetools.com"
export CTP_API_URL="https://auth.europe-west1.gcp.commercetools.com"
export CTP_SCOPES="<comma seperated list of scopes>"

And then constructing a client without arguments:

from commercetools.platform import Client

client = Client()

product = (
    client
    .with_project_key("<your-project-key>")
    .products()
    .with_id("00633d11-c5bb-434e-b132-73f7e130b4e3")
    .get())

print(product)

Releasing

To release this package first (pip) install bump2version and update the CHANGES file. Then update the version (either major/minor/patch depending on the change)

bumpversion --tag <major,minor,patch>

bumpversion is naive because it string replaces, so do a sanity check it didn't accidentally update a Pypi dependency. If not, push the code:

git push --follow-tags

We use GitHub actions so make sure the build succeeds and then go to the tags tab (https://github.com/labd/commercetools-python-sdk/tags).

Click the dots to trigger a release action. Copy the changelog items in the release description and enter the release version. This will upload the release to PyPi.