Skip to main content

A Python library that helps building NGSI-LD entities and interacting with a NGSI-LD Context Broker

Project description

The ngsildclient library

NGSI-LD badge SOF support badge
License Read the Docs
deploy status PyPI Python version

Overview

ngsildclient is a Python library that helps building NGSI-LD entities and allows to interact with a NGSI-LD Context Broker.

The library primary purpose is to ease and speed up the development of a NGSI Agent.

It also can be of interest especially in a Jupyter notebook or in an interactive interpreter :

  • to design new DataModels
  • to explore and manipulate entities stored in a broker
  • for demos, quick proofs of concept or eductional purposes

Key Features

Build NGSI-LD entities

The task of building a large NGSI-LD compliant entity is tedious, error-prone and results in a significant amount of code.

ngsildclient provides primitives to build and manipulate NGSI-LD compliant entities without effort, in respect with the ETSI specifications.

Implement the NGSI-LD API

ngsildclient provides a NGSI-LD API Client implementation.

Acting as a Context Producer/Consumer ngsildclient is able to send/receive NGSI-LD entities to/from the Context Broker for creation and other operations.

The library wraps a large subset of the API endpoints and supports batch operations, queries, subscriptions.

Where to get it

The source code is currently hosted on GitHub at : https://github.com/Orange-OpenSource/python-ngsild-client

Binary installer for the latest released version is available at the Python package index.

Installation

ngsildclient requires Python 3.9+.

pip install ngsildclient

Getting started

The following code snippet builds a NGSI-LD entity related to a measure of air quality in Bordeaux then sends it to the Context Broker.

from ngsildclient import Entity, Client

e = Entity("AirQualityObserved", "Bordeaux-AirProbe42-2022-03-24T09:00:00Z")
e.tprop("dateObserved").gprop("location", (44.84044, -0.5805))
e.prop("PM25", 12, unitcode="GP").prop("PM10", 18, unitcode="GP")
e.prop("NO2", 8, unitcode="GP").prop("O3", 83, unitcode="GP")
e.rel("refDevice", "Device:AirProbe42")
with Client() as client:
    client.upsert(e)

The corresponding JSON-LD payload has been generated.

Already have a NGSI-LD entity available in JSON format ? Simply use Entity.load().

Asynchronous Client

Alternatively you can prefer the Asynchronous Client, typically when user interactivity is not needed and seeking for performance - i.e. writing a real-time NGSI-LD agent.

from ngsildclient import AsyncClient

async with AsyncClient() as client:
    await client.upsert(e)

Documentation

User guide is available on Read the Docs.

Please refer to the Cookbook chapter that provides many HOWTOs to :

  • develop various NGSI-LD Agents collecting data from heterogeneous datasources
  • forge official NGSI-LD Entities from the Smart Data Models initiative

License

Apache 2.0

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

ngsildclient-0.3.2.tar.gz (48.3 kB view hashes)

Uploaded Source

Built Distribution

ngsildclient-0.3.2-py3-none-any.whl (67.1 kB view hashes)

Uploaded Python 3

Supported by

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