The Pinterest SDK currently offers a Python library that supports campaign management and simplifies authentication and error handling. We will be adding functionality supporting organic Pins, shopping, analytics, and more over time. If you have specific feedback about the SDK or requests for additional functionality, please let us know.
Alternatively, you can check out the repository from GitHub. Once the package is downloaded and unzipped, install it:
$ python setup.py install
You can now use the SDK.
Getting Started
For use the client you need set basic variables for that you have two option setup environment variables (using a
.env file or set in your OS) or create a config.json.
Setting up environment variables
To configure the client using environment variables, you must create a .env file using .env.example
as a template. For basic configuration and usage you need to set the following environment variables in the .env file:
Once you have established the environment variables, the client will be instantiated for you automatically.
NOTE:
Setting the PINTEREST_ACCESS_TOKEN (which is valid for thirty days) will require the token value to be replaced when it expires. You will need to manually reinsantiate the client when the access_token expires.
Setting the PINTEREST_REFRESH_ACCESS_TOKEN (which is valid for a year) will allow the SDK to regenerate the new access token whenever it is required.
Setting up config.json
To configure the client using config.json, you must create a config.json file using config.json.example
as a template. For basic configuration and usage you need to set the following key in the config.json file:
Once you have established the keys, the client will be instantiated for you automatically.
NOTE:
Setting up environment variables and config.json will result in the environment variables overriding the keys in config.json
Setting the access_token (which is valid for thirty days) will require the token value to be replaced when it expires. You will need to manually reinsantiate the client when the access_token expires.
Setting the refresh_access_token (which is valid for a year) will allow the SDK to regenerate the new access token whenever it is required.
See pinterest.utils.sdk_exceptions for a list of exceptions which may be thrown by the SDK.
Debugging
If the SDK is not working as expected there might be an issue with the SDK or the Pinterest API server itself. In order to debug and identify the issue, the environment variables for debugging and logging can be enabled.
In order to access or use the client you can import the PinterestSDKClient and call the create_default_client() classmethod:
from pinterest.client import PinterestSDKClient
default_client = PinterestSDKClient.create_default_client()
This will allow you to use the SDK Models without passing a PinterestSDKClient Object.
Creating custom Pinterest SDK Clients
In order to create an object of the PinterestSDKClient you need to pass the access token inside the python code every time you wish to create a client or a combination of the refresh token, app id and app secret. This option is more useful if you wish to work with multiple accounts or clients at the same time.