Python SDK for Tradenity REST API.

Prerequisites

To use the Tradenity SDK, you must have:

  • Working python 2.7x development environment (currently python 3.x is not supported).
  • Active account in Tradenity

For web development, We provide a framework extensions library for both Django and Flask:

Installation

You can install the python SDK using the standard pip tool.

pip install tradenity

Now install your framework specific extension library:

pip install tradenity-flask-ext

pip install tradenity-django-ext

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 session mechanism. The SDK provide implementation for Flask and Django. It’s easy to implement your own for other frameworks, It is a simple 3 method interface.

You must initialize the library before making any API call, preferably before initializing your wsgi application. For example, in a Flask application, you can put the initialization code before calling app.run() method, in django application you can put it in settings.py. Please refer to the framework specific extension library. For a detailed instructions, please refer to the django and flask tutorials (links below).


from tradenity.sdk.http.client import Tradenity

Tradenity.API_KEY = 'sk_xxxxxxxxxxxxxxxxx'

# Now add the framework specific AuthTokenHolder
from tradenity_flask.sdk.ext.auth import FlaskAuthTokenHolder

Tradenity.TOKEN_HOLDER = FlaskAuthTokenHolder

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

Make your First call

The Tradenity SDK is organized into a group of model entitiy classes that corresponds to the REST API’s resources, each encapsulate the operation for a specific entity model, for example to perform operations related to the Brand resource you can use the corresponding tradenity.sdk.entities.Brand class.

Now, just call any method in your code.

from tradenity.sdk.entities import Brand

def brand = Brand.find_by_id("1243-9786786-jhgjtu-789s6i")

Tutorials and sample applications

We provide 2 sample applications, actually it is the same application implemented using 2 frameworks: Flask, and Django.

Camera store sample application live demo

You can find the code at github:

Camera store for django code.

Camera store for flask code.

We also provide a detailed explanation of the code of these sample applications in the form of a step by step tutorials:

Camera store for django tutorial.

Camera store for flask tutorial.