Kladama API package
Project description
Kladama API for Python
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
Release history Release notifications | RSS feed
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
Close
Hashes for kladama_api-0.9.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4f458454d9a7f925d18c5e9a191b71ccf48fa0af561c3ccdde7ea607e395995 |
|
MD5 | a906797c8c050e77f73804663b4e5ed7 |
|
BLAKE2b-256 | 49d4e4723c22c808d3e152c0efeb573b60f6dbc56976301df94661d5d5ddcfb3 |