Skip to main content
Kpler API and SDK introduction

A brief introduction to the Kpler REST API and Python SDK.

Anil Sivarajah avatar
Written by Anil Sivarajah
Updated over a week ago

Welcome to the Kpler API, to help you decide which method of data retrieval to use and how to get started, please see the sections below.

We also have a dedicated API help centre available here.


REST API vs SDK

The two methods of accessing the Kpler API are via our REST API and our Python SDK - the details of both are listed below:

Feature

REST API

SDK

Language

Any

Python 3.7+

Output

Semicolon separated CSV (JSON for /trades/updates)

Authentication

Basic or Token

Basic only

Differences between the REST API and SDK

Most endpoints available on the REST API are or will also be available on the Python SDK, therefore it remains a personal preference; however some of the key differences are:

  • The SDK has built in helper classes to construct the queries for you

  • The REST API can be implemented in any language

  • The SDK can be used alongside Python libraries like NumPy, Matplotlib etc to manipulate Kpler data in situ.

  • The REST API can be easily plumbed into Excel, PowerBI, Tableau etc.


Getting Started: REST API

The REST API documentation can be found using this link and selecting the relevant commodity you wish to access.

Authentication

There are two ways to authenticate on the Kpler REST API, by token authentication or by basic authentication using the same username and password as you use if you use other Kpler products.

To retrieve your token, following the steps on the API documentation, simply create a POST request to the /v1/login endpoint with your username and password contained in the request body like so:

{ 
"email": "your_mail@example.com",
"password": "your_password"
}

After creating your token you can include it in the request headers using the format

{
"Authorization" : "Bearer yourToken"
}

Otherwise, to use basic authentication simply add the base64 encoded version of your credentials in the format: your_username:your_password and add the following JSON to your header.

{
"Authorization": "Basic Y3VzdG9tZXJAZW1haWwuY29tOm1Zc3RSb25nUDRzc3cwUmQ="
}

From then you're ready to use the documentation to create the URLs to be pointed at our REST API!


Getting Started - Python SDK

The Kpler SDK documentation can be accessed using this link.

First things first, let's get the SDK installed using pip (follow this link if you need help with getting your environment created) using the code:

pip install kpler.sdk

Then, using basic authentication, set up your config at the top of your script or Jupyter notebook.

from kpler.sdk.configuration import Configuration 
from kpler.sdk import Platform

config = Configuration(Platform.Liquids, "<your email>", "<your password>")

Note: you can select other platforms using Platform.LNG, Platform.LPG or Platform.Dry

Note: It is not required to include the <> in your credentials.


Now you're ready to use the documentation to create your first query - don't forget to use the output from the helper class - a little tip, you can use import pandas as pd after installing Pandas to use all of the native Pandas methods on the returned DataFrame - otherwise you can simply print the DataFrame to see the results.


Security

In order to use the Excel add-in or the API/Python SDK, your IT must allow HTTPS requests (port 443) to the following addresses/IPs:

Once this is completed, you should be able to use the Kpler API, SDK or Excel Add-In as usual. If you're still faced with error messages after completing these steps, please reach out to cs@kpler.com with the query you're using and any error messages to allow us to investigate further for you.


Notes and FAQ

  • If you require a mapping document for geographical entities or our commodity, products and grades tree please reach out to the Customer Success team on cs@kpler.com as these cannot currently be queried through the API or SDK.

  • There is a returned record limit of 100,000 records on LNG, LPG and Dry, 200,000 on Liquids.

  • You can select your preferred language from the top of the REST API docs to see example code in your language - this might make it easier for you to get started!

  • For a list of Frequently Asked Questions on our API endpoints please check out this article.

  • In order to upgrade the Python SDK you can use the code:
    โ€‹pip install kpler.sdk --upgrade
    To be automatically informed of updates, simply add:
    โ€‹log_level="INFO"
    to the end of your config object, otherwise Kpler will notify you about new SDK releases.

  • Tokens for authentication periodically expire, you can repeat the steps listed above to generate a new token.


If you have any questions or need help getting set up, just give our Customer Success team an email to cs@kpler.com and someone will be happy to lend a hand.

Did this answer your question?