What is the purpose of Client's environment in Python SDK?

Hi,

I’m using Square’s Python SDK. In the SDK, the Client needs a parameter called environment. I want to know why we need this parameter because the token already points at an environment. You can determine the environment based on the token.

So what if I used a sandbox’s token and didn’t set the environment parameter?

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Square Sandbox
Python SDK
Postman

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The environment parameter in the Square Python SDK is used to determine the base URL for the API calls. If you set the environment to ‘sandbox’, the SDK will make API calls to the Sandbox environment (https://connect.squareupsandbox.com). If you set it to ‘production’, the SDK will make API calls to the Production environment (https://connect.squareup.com).

If you use a Sandbox token but don’t set the environment parameter, the SDK will default to the Production environment. This will result in errors because the Sandbox token is not valid in the Production environment. Therefore, it’s important to ensure that the environment parameter matches the environment of your token.

This answer was reviewed by @Bryan-Square.