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. "List available Variables" example.

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 (AoI)

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_name('<aoi name>')\
    .with_description("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 check if a GeoJson data can be used as a valid AoI in Kladama

import kladama as kld

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

query = kld.Helpers\
            .check_aoi({
                "type": "FeatureCollection",
                "features": [
                    {
                        "type": "Feature",
                        "properties": {
                            "id": "5b8c9e286e63b329cf764c61",
                            "name": "Farm 455"
                        },
                        "geometry": {
                            "type": "Polygon",
                            "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).get(query)
if isinstance(response, kld.Error):
    print(response.__str__())
else:
    print('Valid: ', response['valid'])
    for message in response['messages']:
        print(message)

How to create a Periodic Subscription to a variable

# create 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('<var name>')\
    .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 last data from a periodic subscription

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.6-py3-none-any.whl (9.4 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