Skip to main content

Kladama API package

Project description

Kladama API for Python

Master Build

Python API for Kladama Services Integration

How to install it

You can install the API through PIP

pip install kladama-api

How to start using it

First, you must to authenticate through a API Token that must be provided to you. This authentication process returns a session object that must be used to create a Context object.

# retrieve all available variables

import kladama as kld

env = kld.Environments().prod
api_token = '<your provided token>'
session = kld.authenticate(env, api_token)

query = kld.Query().var

variables = kld.Context(session).get(query)
for var in variables:
    print(var.name, '-', var.description, 'in', var.link)

How to add an area of interest

# create a periodic subscription

import kladama as kld

env = kld.Environments().prod
api_token = '<your provided token>'
session = kld.authenticate(env, api_token)

operation = kld.Operations()\
    .add_aoi\
    .for_user('<your user>')\
    .with_aoi_id('<aoi id>')\
    .with_name("Test AOI")\
    .with_category("Test")\
    .with_features({
        "type": "FeatureCollection",
        "name": "Test AoI",
        "features": {
            "type": "Feature",
            "properties": {
                "id": "5b8c9e286e63b329cf764c61",
                "name": "field-1",
                "geometry": {
                    "type": "MultiPolygon",
                    "coordinates": [
                        [
                            [
                                [-60.675417,-21.854207],
                                [-60.675394,-21.855348],
                                [-60.669532,-21.858799],
                                [-60.656133,-21.85887],
                                [-60.656118,-21.854208],
                                [-60.675417,-21.854207]
                            ]
                        ]
                    ]
                },
            }
        }
    })

response = kld.Context(session).execute(operation)
if not isinstance(response, kld.Success):
    print(response.__str__())

How to subscribe to a variable

# create a periodic subscription

import kladama as kld

env = kld.Environments().prod
api_token = '<your provided token>'
session = kld.authenticate(env, api_token)

operation = kld.Operations()\
    .periodic_subsc\
    .for_user('<your user>')\
    .with_variable('ecmwf-era5-2m-ar-max-temp')\
    .with_source('ECMWF')\
    .with_operation('mean')\
    .with_aoi('<aoi name>')

response = kld.Context(session).execute(operation)
if isinstance(response, kld.Success):
    code = response.result['code'] # the code is the id of the subscription
else:
    print(response.__str__())

How to get a subscription

# create get subscription info

import base64 as b64
import kladama as kld

env = kld.Environments().prod
api_token = '<your provided token>'
session = kld.authenticate(env, api_token)

query = kld.Query()\
    .subsc\
    .by_user('<your user>')\
    .filter_by('<subscription code>')\
    .last

response = kld.Context(session).get(query)
if isinstance(response, kld.Error):
    print(response.__str__())
else:
    print('Name: ', response.name, ' Binary Content:\n', b64.b64encode(response.content).decode('utf-8'))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

kladama_api-0.9.5-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page