All Projects → square → Connect Python Sdk

square / Connect Python Sdk

Licence: apache-2.0
Python client library for the Square Connect APIs

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Connect Python Sdk

Ng Suggest
AngularJS module to provide Typeahead via OpenSearch Suggestions
Stars: ✭ 9 (-80%)
Mutual labels:  deprecated
Os Tmpdir
[DEPRECATED] Node.js os.tmpdir() ponyfill
Stars: ✭ 31 (-31.11%)
Mutual labels:  deprecated
Helm Registry
The helm registry to store and deliver charts (Deprecated since compass v2.9)
Stars: ✭ 36 (-20%)
Mutual labels:  deprecated
Deobfuscator
[Not work] Deobfuscate obfuscated binaries!
Stars: ✭ 11 (-75.56%)
Mutual labels:  deprecated
Prey Bash Client
DEPRECATED - Project no longer supported, please consider using https://github.com/prey/prey-node-client instead
Stars: ✭ 882 (+1860%)
Mutual labels:  deprecated
Brunch With Vue
[deprecated] A skeleton application utilizing vue, vuex, vue-resource and vue-router.
Stars: ✭ 32 (-28.89%)
Mutual labels:  deprecated
Otc Tools
(Deprecated) Simple bash/curl/jq based command line tool using the OpenStack and OTC specific REST APIs.
Stars: ✭ 26 (-42.22%)
Mutual labels:  deprecated
Tmwa Client Data
DEPRECATED: The data used by the ManaPlus client for the tmwAthena server used by The Mana World Legacy. All further development will take place in the "client-data" repo.
Stars: ✭ 42 (-6.67%)
Mutual labels:  deprecated
Overwatch Js
Overwatch NodeJS API : Retrieve informations about heroes/players from Overwatch Official Website
Stars: ✭ 27 (-40%)
Mutual labels:  deprecated
Libvirt
DEPRECATED Vanilla dockerized libvirt image, used as a base for kubevirt
Stars: ✭ 34 (-24.44%)
Mutual labels:  deprecated
Grunt Csswring
DEPRECATED. Minify CSS files using PostCSS-based CSSWring
Stars: ✭ 12 (-73.33%)
Mutual labels:  deprecated
Startssl api
DEPRECATED A python/CLI API for some StartCom StartSSL functions
Stars: ✭ 14 (-68.89%)
Mutual labels:  deprecated
Ng2 Typeahead
Autocomplete component for Angular 2
Stars: ✭ 33 (-26.67%)
Mutual labels:  deprecated
Sqlite Provider
SQLite3 provider for Vapor
Stars: ✭ 11 (-75.56%)
Mutual labels:  deprecated
Strano
Strano is a web UI to run any tasks (but mostly Capistrano) from any of your git repo.
Stars: ✭ 36 (-20%)
Mutual labels:  deprecated
Madalynnplumbundle
The deploy bundle using Plum for Symfony2
Stars: ✭ 26 (-42.22%)
Mutual labels:  deprecated
Finder colors
Set the color of files/folders for OSX Finder from the command line.
Stars: ✭ 31 (-31.11%)
Mutual labels:  deprecated
Findbugs Plugin
Jenkins findbugs plugin
Stars: ✭ 43 (-4.44%)
Mutual labels:  deprecated
Multiple Scms Plugin
Stars: ✭ 39 (-13.33%)
Mutual labels:  deprecated
Sarama Cluster
Cluster extensions for Sarama, the Go client library for Apache Kafka 0.9 [DEPRECATED]
Stars: ✭ 969 (+2053.33%)
Mutual labels:  deprecated

Square logo

Square Connect Python SDK - RETIRED


Build Status PyPI version Apache-2 license

NOTICE: Square Connect Python SDK retired

The Square Connect Python SDK is retired (EOL) as of 2019-08-15 and will no longer receive bug fixes or product updates. To continue receiving API and SDK improvements, please follow the instructions below to migrate to the new Square Python SDK.

The old Connect SDK documentation is available under the /docs folder.





Migrate to the Square Python SDK

Follow the instructions below to migrate your apps from the deprecated squareconnect library to the new square library.

Install the new library

Install the latest Square Python SDK using pip:

pip install squareup

Update your code

  1. Change all instances of import 'squareconnect' to import 'square'.
  2. Replace models with plain Python dictionary equivalents.
  3. Update client instantiation to follow the method outlined below.
  4. Update code for accessing response data to follow the method outlined below.
  5. Check response.is_success or response.is_error rather than rescuing exceptions for flow control.

To simplify your code, we also recommend that you use method chaining to access APIs instead of explicitly instantiating multiple clients.

Client instantiation

from square.client import Client

square = Client(access_token='YOUR ACCESS TOKEN')

response = square.API.ENDPOINT(body=BODY)

Accessing response data

if response.is_success():
  print({response.body})
elif response.is_error():
  print({response.errors})

An example code migration

As a specific example, consider the following code for creating a new customer from this dictionary:

new_customer = {
  'given_name': 'Ava',
  'address': {
    'address_line_1': '555 Electric Ave',
    'locality': 'Los Angeles',
    'country': 'US'
  }
}

With the deprecated squareconnect library, this is how you instantiate a client for the Customers API, format the request, and call the endpoint:

from squareconnect import ApiClient
from squareconnect.rest import ApiException
from squareconnect.apis.customers_api import CustomersApi
from squareconnect.models.create_customer_request import CreateCustomerRequest

# Instantiate and initialize the client
api_client = ApiClient()
api_client.configuration.access_token = 'YOUR ACCESS TOKEN'

# Get an instance of the Square API you want call
api_instance = CustomersApi(api_client)

# Build the request
create_customer_request = CreateCustomerRequest(
  given_name=new_customer['given_name'],
  address=new_customer['address'],
)

# Call create_customer method to create a new customer and handle the response
try:
  api_response = api_instance.create_customer(create_customer_request)
  print(f"Success: {api_response.customer}")
except ApiException as err:
  print(f"Exception when calling CustomersApi->create_customer: {err}")

Now consider equivalent code using the new square library:

from square.client import Client

# Instantiate the client
client = Client(access_token='YOUR ACCESS TOKEN')

# Call create_customer method to create a new customer
result = client.customers.create_customer(new_customer)

# Handle the result
if result.is_success():
  # Display the response as text
  print(f"Success: {result.text}")
# Call the error method to see if the call failed
elif result.is_error():
  print(f"Errors: {result.errors}")

That's it! What was once a multi-block process can be handled in 2 lines of code and an if/elif block. Migrating to the square library reduces boilerplate and lets you can focus on the parts of your code that really matter.




Ask the community

Please join us in our Square developer community if you have any questions!

Square Python SDK

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].