Skip to main content

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.

Release files for klab-client-py 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for klab-client-py 0.3.0
File Size Uploaded
klab_client_py-0.3.0.tar.gz 48.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for klab-client-py 0.3.0
File Interpreter ABI Platform
klab_client_py-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 98.0 kB

Release files / klab_client_py-0.3.0.tar.gz

Download URL klab_client_py-0.3.0.tar.gz
Size 48.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b98c5dc370194b04238292e86c5759bdcf263331af5c2cf820e418470d25072
BLAKE2b-256 checksum
How to use checksums
1e0d42611cae9d01f22f4a53bceb3216498eb6f3aab40bff11299ac2d4cd4c60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / klab_client_py-0.3.0-py3-none-any.whl

Download URL klab_client_py-0.3.0-py3-none-any.whl
Size 49.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd4aa976126bcc39997a7378e512f12c4eb0e54cb80a5da652446bcbd0708043
BLAKE2b-256 checksum
How to use checksums
a28e9aa1f2807a93c160c8519f82a1d8728e8c596a656618e17346fe67fcf6c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.3.2

2 release files

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page