Skip to main content

SDK for Sweetspot Team to interact with backend APIs

Project description

Sweetspot Python SDK

This Python library helps Sweetspot developers interact with their backend APIs to modify shops, merchants, and consumers.

Installation

pip install sweetspot-sdk 

Client

The API client can be initialized as follows:

from sweetspot.client import Client 

client = Client(
    csrf_refresh_token='csrf_refresh_token', 
    csrf_access_token='csrf_access_token', 
    access_token_cookie='access_token_cookie', 
    refresh_token_cookie='refresh_token_cookie',
    environment='development')

API calls return an ApiResponse object that includes the following fields:

Field Description
status_code Status code of the HTTP response
reason_phrase Reason phrase of the HTTP response
headers Headers of the HTTP response as a dictionary
text The body of the HTTP response as a string
request HTTP request info
errors Errors, if they exist
body The deserialized body of the HTTP response
cookies The deserialized cookies of the HTTP response

Make Calls with the API Client

from sweetspot.client import Client

client = Client(
    csrf_refresh_token='csrf_refresh_token', 
    csrf_access_token='csrf_access_token', 
    access_token_cookie='access_token_cookie', 
    refresh_token_cookie='refresh_token_cookie',
    environment='development')

category_result = client.category.get_all_categories()
if category_result.is_success():
    categories = category_result.body

Authenticating the API Client

The client must obtain access tokens and cookies in order to call protected endpoints.

from sweetspot.client import Client 

client = Client() 

login_payload = {
    'email':email,
    'password':password
}

authentication_result = client.authentication.get_authentication_information(login_payload)
if authentication_result.is_success(): 
    client.update_config(**authentication_result.cookies)

#call protected endpoint 

category_result = client.category.get_all_categories()
if category_result.is_success():
    categories = category_result.body

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sweetspot-sdk-0.0.8.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

sweetspot_sdk-0.0.8-py3-none-any.whl (23.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page