Announcing Square’s New Python SDK
Use the new Python SDK to integrate with Square APIs
We’re excited to announce the release of our new Python SDK. Run your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, Orders, and more.
To install the Python SDK, just pip install squareup
from the command line. You can alternatively clone the SDK from GitHub and install it using python setup.py install --user
. Next, all you need to do is provide your access token and you’re ready to use Square APIs.
from square.client import Client
client = Client(
access_token='SANDBOX_ACCESS_TOKEN',
environment='sandbox',
)
api_locations = client.locations
result = api_locations.list_locations()
One of the great features in the new Python SDK is that the response
object contains new rich information about both the request and response. These details can be used for control flow and debugging.
Below are examples of checking the basic response status.
result.is_success()
#=> true
result.is_error()
#=> false
result.errors
#=> []
result.reason_phrase
#=> OK
result.status_code
#=> 200
If you were previously using the squareconnect
SDK, you might be wondering how squareup
compares. Let’s take a look! For example, let’s create the following customer along with their address:
customer = {
"given_name": "Amelia",
"family_name": "Earhart",
"email_address": "[email protected]",
}
First, let’s look at how we used to create a customer with the legacy squareconnect
SDK:
from __future__ import print_function
import squareconnect
from squareconnect.rest import ApiException
from squareconnect.apis.customers_api import CustomersApi
api_instance = CustomersApi()
api_instance.api_client.configuration.host = "https://connect.squareupsandbox.com"
api_instance.api_client.configuration.access_token = "SANDBOX_ACCESS_TOKEN"
try:
# ListLocations
api_response = api_instance.create_customer({
"given_name": "Amelia",
"family_name": "Earhart",
"email_address": "[email protected]",
})
print(api_response.customer)
For comparison, let’s create the same customer with the new squareup SDK:
from square.client import Client
client = Client(
access_token='SANBOX_ACCESS_TOKEN',
environment='sandbox',
)
api_customers = client.customers
result = api_customers.create_customer({
"given_name": "Amelia",
"family_name": "Earhart",
"email_address": "[email protected]",
})
print(result.body["customer"])
That’s all there is to it!
As you can see, the new squareup
Python SDK interface is much simpler and less verbose. The new SDK also ships with a ton of usability and debugging features.
Give the squareup
Python SDK a try today by installing it with pip install squareup
.
With the new squareup
SDK it’s easier than ever to use Square as a platform to run your business with Python. We can’t wait to see what you’ll build! If you have any questions or feedback, drop by our developer community. We’d love to hear from you.