- All required dependencies for this SDK must be installed in your python virtual environment.
- These dependencies are listed inside the requirements.txt file within this repository.
- You may use "pip" to install these in your virtual environment.
This can be done in either of two ways:
- Copy the SDK folder in this repository, and paste it as a new folder inside your Python project
- For quick use, paste this in the root directory of your Python project. However,
- It's recommended to paste this inside the virtual environment folder of your Python project (Refer to the section below: Add SDK folder in your Python virtual environment) OR
- Create a build (python wheel) within this repository and install the wheel in your project
- This approach is helpful, if you make any changes to the SDK and want to use this in your project instead. (Refer to section: )
Important: In either of above way to add the SDK, the dependencies (listed in requirements.txt) must be installed in the python environment in which the SDK will be used.
Add the folder in your Python virtual environment
- Open PythonSDK and copy the "SDK" directory inside it
- Paste above copied directory inside your project
- Recommended: Your repository should have a virtual environment first.
- Suppose name of virtual environment in the Python client repository is "venv", then:
- Paste the above copied directory inside: venv/lib/Python3.x/site-packages
Create a Python wheel on your system and install the wheel.
- Clone or download this repository
- Activate a virtual environment in the PythonSDK folder
- Build a wheel using setuptools:
python3 setup.py sdist bdist_wheel
- This creates a Python wheel (.whl file) inside a "dist" folder inside the PythonSDK repository.
- Copy the absolute path to this wheel file and install this file in your Python project.
- For example using pip:
pip install pythonSDK-0.0.1-py3-none-any.whl
- For example using pip:
All requests made using this SDK require authentication based on credentials provided for specific Properties.
- Each request requires a valid Property ID (propid)
- If credentials are not registered for the Property ID being used, then the requests will fail.
Before using any requests from the SDK, ensure the following:
- You have the SC-HMAC credentials for the Property which you will pass to the request.
- You can request these from our representative (admin or tech team)
- The SC-HMAC credentials include an Access Key and a Secret Key
- The credentials for the Property ID being used in the request are registered.
- This only needs to be done once.
- Do this by calling the appropriate SDK utility function (register_credentials_for_property).
- This utility stores the given Access Key and Secret Key for the Property ID used in the request.
- For example, refer to below section: "Register credentials for a property".
Note: You may remove the stored credentials for a Property by calling the appropriate SDK utility function
- Refer to below section: "Deregister credentials for a property"
Registration of credentials for a property is done so that you can access the details pertaining to that property if credentials get validated. Example:
from SDK.utils import register_credentials_for_property
response = register_credentials_for_property(property_id=<property_id>, access_key=<access_key>, secret_key=<secret_key>)
# property_id, access_key and secret_key need to be placed in the corresponding placeholders.
Deregistration of credentials for a property is done so that you can delete the credentials pertaining to a property which may no longer be in use.
Example:
from SDK.utils import deregister_credentials_for_property
response = deregister_credentials_for_property(property_id=<property_id>)
# property_id need to be placed in the corresponding placeholder.
from SDK.SCGridsServices.API import *
import json
grids = SCGrids()
Org='SMARTCLEAN'
Pid='test_pid'
PropId = 'test_propid'
json_data = {
"LID": "{{lid}}"
}
jsondata = json.dumps(json_data)
zones = grids.listZonesByLevel(org=Org, pid=Pid, expJson=jsondata)
Pid = 'scnoop'
#For using the Sync Client:
Property = grids.readProperty(org=Org, pid=Pid, propid=PropId, client='Sync')
#For getting the Sync Client's data:
propertyData = Property.json()
#For getting the Sync Client's status code:
propertyStatusCode = Property.status_code
# For using the Async Client:
Property = grids.readProperty(org=Org, pid= Pid, propid=PropId, client='Async')
# Or
Property = grids.readProperty(org=Org, pid= Pid, propid=PropId)
# Since Async Client is the default client
#For getting the Sync Client's data:
propertyData = json.loads(Property.body)
#For getting the Sync Client's status code:
propertyStatusCode = Property.status
This dependency must be installed with a custom option (see requirements.txt) If you install it manually (forgetting the custom option) it may cause an error on some machines or operating systems and you may see the following error when using the SDK:
ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend.
Solution:
Install pycurl with the required custom option: pip install pycurl --global-option="--with-openssl"
In case you get errors related to compiling openssl, try adding the following variables to your system path:
- Set CPPFLAGS to your openssl/include folder
export CPPFLAGS=-I/usr/local/opt/openssl/include
- Set LDFLAGS to your openssl/lib folder
export LDFLAGS=-L/usr/local/opt/openssl/lib
Please create an issue in this github repository with the details