Skip to main content

No project description provided

Project description

NGILIVE SDK

Usage

Useful library to develop against the NGI Live API.

It helps you get access to the API by doing all the difficult auth things.

Additionally it provides nice type hinted bindings for the API endpoints, so you can follow code completion instead of reading documentation!

from ngilive import NGILive

nl = NGILive()


sensor_response = nl.sensor_search(
    20190539,
    logger="IK50",
    unit="V",
)

The first time you run it, you will see an output like this in your terminal. Perform the log in as prompted, and you will not see it again until your access has expired.

[18:41:13] ngilive.auth INFO: Please complete the authentication in your browser: https://keycloak.ngiapi.no/auth/...

Example Queries

Query Sensor Metadata

from ngilive import NGILive

nl = NGILive()


sensor_response = nl.sensor_search(
    20190539,
    logger="IK50",
    unit="V",
)

Example response:

{
  "sensors": [
    {
      "name": "18V_IK50",
      "unit": "V",
      "logger": "IK50",
      "type": "zBat18V",
      "pos": {
        "north": null,
        "east": null,
        "mash": null,
        "coordinateSystem": {
          "authority": "EPSG",
          "srid": null
        }
      }
    },
    {
      "name": "3V_IK50",
      "unit": "V",
      "logger": "IK50",
      "type": "zBat3V",
      "pos": {
        "north": null,
        "east": null,
        "mash": null,
        "coordinateSystem": {
          "authority": "EPSG",
          "srid": null
        }
      }
    }
  ]
}

Query datapoints

datapoints = nl.datapoint_search(
    project_number=20190539,
    start=datetime.now(tz=UTC) - timedelta(days=1),
    end=datetime.now(tz=UTC),
    logger="IK50",
    unit="V",
)

Authentication

Authorization Code

You can use this library to obtain an access token and call the API. It will open the browser for you, and ask you to log in to geohub.

The below example is useful if you want to control the HTTP client yourself, for example using requests or httpx libraries.

import httpx

from ngilive.auth import AuthorizationCode

auth = AuthorizationCode()
access_token = auth.get_token()

response = httpx.get(
    "http://api.test.ngilive.no/projects/20190539/sensors",
    headers={"Authorization": f"Bearer {access_token}"},
)

Client Credentials

This example uses client_id and client secret instead of signing in in the browser. It is useful in cases where an automatic job should call the API, which cannot log in via the browser. For other usecases, use AuthorizationCode instead.

You can also use the ClientCredentials helper to get an access token like in the above Authorization code example.

from ngilive import NGILive
from ngilive.auth import ClientCredentials

auth = ClientCredentials(
    client_id="data-api-test-client",
    client_secret="<client secret>",
)

nl = NGILive(auth=auth)

# Now you can query without logging in
# sensor_response = nl.query_sensors(20190539)

Development

Generate documentation:

pdoc -t docs/templates/ \
    -o build/docs \
    src/ngilive/__init__.py \
    src/ngilive/schema.py \
    src/ngilive/auth.py \
    src/ngilive/config.py \

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

ngilive-0.5.2.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

ngilive-0.5.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file ngilive-0.5.2.tar.gz.

File metadata

  • Download URL: ngilive-0.5.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for ngilive-0.5.2.tar.gz
Algorithm Hash digest
SHA256 993736e076f0a8145ff52be6d4a83e7656c1beb5478f7944abab2398321d5f5b
MD5 66377381c36c3f26c4b8153627024317
BLAKE2b-256 913ea6451ca676d23af9b879fade8605fdff3fae5af4aa884675f47e529053ed

See more details on using hashes here.

File details

Details for the file ngilive-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: ngilive-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for ngilive-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f83a4bd0e7ddd92a4cd91b1747b0087b221b815a41e30924d18b1819467fd383
MD5 d584e0ee62b14b8f2f971f3482030b55
BLAKE2b-256 5d563581db7390ffb5f749b531669988c3fbdbb149c9d980ce93aee30d1e01d8

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