Skip to main content

Python client to interact with a running k.LAB Engine.

Project description

k.LAB CLient Python

A Python client library to interact with a running (local or remote) k.LAB Engine.

This package is a python client for k.LAB. It allows registered users of k.LAB to make observations on the k.LAB semantic web from a Python program using the REST API. After creating a spatial/temporal context root observation as a context, you can submit concepts to be observed in it and the relative observations will be made at the server side and returned. Depending on the semantics submitted, the results will consists of different scientific artifacts that can be exported or inspected as needed through the API.

While the API (both k.LAB's public REST API and the interfaces in this package) should be stable, this code is young - features are still missing and bugs certainly remain. Please submit Github issues as needed.

This README assumes knowledge of k.LAB and semantic modeling. An introduction to both is available as a technical note while more extensive documentation is developed.

Installation

The module can be installed through pip as:

pip install klab-client-py

Usage

Usage example: observe elevation on a given region

Note that asyncio is used to handle async elaborations.

  1. add necessary imports and create a new client instance
from klab.klab import Klab
from klab.geometry import GeometryBuilder
from klab.observable import Observable
from klab.observation import Observation
from klab.utils import Export, ExportFormat
import asyncio

klab = Klab.create()
  1. define a geometry to use as context through its WKT definition
ruaha = "EPSG:4326 POLYGON((33.796 -7.086, 35.946 -7.086, 35.946 -9.41, 33.796 -9.41, 33.796 -7.086))"
  1. create a semantic type and a geometry
obs = Observable.create("earth:Region")
grid = GeometryBuilder().grid(urn= ruaha, resolution= "1 km").years(2010).build()
  1. submit them to the engine and obtain the context
ticketHandler = self.klab.submit(obs, grid)
context = await ticketHandler.get()
  1. create the elevation observable and submit it to the context
obsElev = Observable.create("geography:Elevation")
ticketHandler = context.submit(obsElev)
elevation = await ticketHandler.get()
  1. export the observation to a geotiff
path = "your path here"
elevation.exportToFile(Export.DATA, ExportFormat.BYTESTREAM, path)

For more examples have a look at the testcases in the repository.

Project details


Download files

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

Source Distribution

klab-client-py-0.1.2.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klab_client_py-0.1.2-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file klab-client-py-0.1.2.tar.gz.

File metadata

  • Download URL: klab-client-py-0.1.2.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klab-client-py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 38d1c98ae10cdd9f4c18f41d7d4e157e965a54b7879dbaa586aad68d6a1a6abd
MD5 126646ebfa81c92adb6de1f18060a635
BLAKE2b-256 12dda28bc8a30b04e6ca4b4789d4dfd703551e6dbf89f6b5f5abc01d4f689e66

See more details on using hashes here.

File details

Details for the file klab_client_py-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: klab_client_py-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for klab_client_py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1135492b82abaf0fa5417f7564694246b925a7083f4fbc6be41bf56229f234cd
MD5 68092eb0854c2c0e3cfb65ffddd00f78
BLAKE2b-256 d5023f126691efce0952f07e62779bd187f202d2e87be0ca41b1125940f33cb8

See more details on using hashes here.

Supported by

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