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. "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.Queries().var
response = kld.Context(session).get(query)
if isinstance(response, kld.Success):
for var in response.result:
print(var.name, '-', var.description, 'in', var.link)
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.Services().validate_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.result['valid'])
for message in response.result['messages']:
print(message)
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)
transaction = kld.Transactions()\
.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": "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).execute(transaction)
if not isinstance(response, kld.Success):
print(response.__str__())
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)
transaction = kld.Transactions()\
.periodic_subsc\
.for_user('<your user>')\
.with_variable('<var name>')\
.with_operation('MEAN')\ # could be any other Spatial Operation (MIN, MAX, STD, etc)
.with_aoi('<aoi name>')
response = kld.Context(session).execute(transaction)
if isinstance(response, kld.Success):
if response.type == 'ok':
code = response.result['code'] # property 'code' contains ID of new created subscription
print("New subscription code: ", code)
else:
print("Redirect to: ", response.result['href']) # property 'href' contains URI of identical subscription resource
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.Queries()\
.subsc\
.by_user('<your user>')\
.by_key('<subscription code>')\
.results\
.last
response = kld.Context(session).get(query)
if isinstance(response, kld.Error):
print(response.__str__())
elif response.result is None:
print('response is successful but empty')
else:
assert isinstance(response.result, kld.BinaryResult)
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-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1ccc3a60f8be5c6e0c68e6b7a4341ee66a2c00e566214776b47e92cd75b967 |
|
MD5 | 7d63229e75317b307b1b20929f8ee247 |
|
BLAKE2b-256 | 5840f875f1f1099d1486ddb0eb7d306fc5b244766213b7e345164045e6e2ce40 |