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:
- Flask extensions https://github.com/tradenity/python-sdk-flask-ext.
- Django extensions https://github.com/tradenity/python-sdk-django-ext.
You can install the python SDK using the standard
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
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
app.run() method, in django application you can put it in
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
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:
You can find the code at github:
We also provide a detailed explanation of the code of these sample applications in the form of a step by step tutorials: