Download and install the python SDK and intro to its structure.

Live demo

Here you can find live demo of the Camera store sample application. This is the application we are going to build here.

Prerequisites

To follow along with this tutorial, you have to have:

  • Active account in Tradenity
  • Create the sample “Camera store”, and load the sample data (This option is available on the create store page).
  • Have a working python development environment (python 2.7x installation, your IDE of choice)
  • Basic familiarity with the Flask framework.

Setup your credentials

First of all, you have to get API keys for your store, you can find it in your store Edit page. To get there navigate to the stores list page, click on the Edit button next to your store name, scroll down till you find the API Keys section.

Initialize the library

With the API key in hand, you can initialize the Tradenity client. Tradenity client needs the API key and an instance of AuthTokenHolder which is an object that makes Tradenity session integrates with the web framework’s (Flask in our case) session mechanism. The SDK provide implementation for Flask and Django and it’s easy to implement youe own

You must initialize the library before making any API call. In a Flask application, you can put the initialization code before calling app.run() method.

camerastore/main.py


from camerastore import app
from tradenity.sdk.ext.flask.auth import FlaskAuthTokenHolder
from tradenity.sdk.http.client import Tradenity

Tradenity.initialize('sk_1234567', auth_token_holder=FlaskAuthTokenHolder)

Make sure to replace the api keys with the ones for your store, otherwise you will get authentication error

Introducing CameraStore sample application

CameraStore application is a typical e-store web application, a web store for a camera shop.

The application code is placed into camerastore package, which is divided into these modules

  • shop.py : navigating the and browsing the store, the corresponding templates are in the camerastore/templates directory.
  • cart.py : Shopping cart manipulation code. the corresponding template camerastore/templates/cart.html.
  • account.py : login management and registering new customers. the corresponding templates are in the camerastore/templates/account directory.
  • orders.py : placing new order, viewing list and details of customer’s past orders. the corresponding templates are in the camerastore/templates/orders directory.