Python

This page documents an earlier firmware release. Read this page for the latest release

The Python package blickfeld_qb2 is available pre-built on PyPI. It returns point clouds as NumPy arrays without copying the data, fast enough for live streaming and processing.

Install the library

pip install -U blickfeld_qb2
Import the library
import blickfeld_qb2

Connect to the sensor

The Channel opens an encrypted gRPC connection to the hostname or the IP address of the sensor. The TokenFactory signs in with an application key.

An encrypted and authenticated channel to the sensor
import blickfeld_qb2

# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
    application_key_secret="application-key-for-qb2-xxxxxxxxx"
)

# Open a secure & authenticated connection to the sensor
with blickfeld_qb2.Channel(
        fqdn_or_ip="qb2-xxxxxxxxx",
        token=token_factory
    ) as channel:
    # Call methods of services here
    # ..
    pass

Create an application key first. In the example, replace application-key-for-qb2-xxxxxxxxx with its secret, and qb2-xxxxxxxxx with the hostname or the IP address of your sensor.

If the application key is invalid, the first API call on the channel fails with the gRPC status code 5, NOT_FOUND.

Pass the serial_number of the sensor as well to check that the channel connects to that particular sensor. Without it, the channel only checks that it connects to a Blickfeld device.

Send a request

This example reads the firmware version with get_status() of the Firmware service in blickfeld_qb2.system.services.

import blickfeld_qb2

# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
    application_key_secret="application-key-for-qb2-xxxxxxxxx"
)

# Open a secure & authenticated connection to the sensor
with blickfeld_qb2.Channel(
        fqdn_or_ip="qb2-xxxxxxxxx",
        token=token_factory
    ) as channel:
    # Request the firmware status
    response = blickfeld_qb2.system.services.Firmware(channel).get_status()
    # Extract the firmware version
    firmware_version = response.status.installed_firmware_info
    # Print the firmware version
    print(firmware_version)

Each response is an object with nested objects, as defined in the API reference. One channel serves any number of requests. Output, one field per line:

FirmwareInfo(
    label='HENNING v3.2.4',
    version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
    allowed_downgrade_version=Version(major=3, patch=11)
)

The version of a released firmware also shows is_release=True.

Send requests asynchronously

The asynchronous variant of each method has the prefix async_:

import asyncio
import blickfeld_qb2

async def main():
    # Create token factory using an application key
    token_factory = blickfeld_qb2.TokenFactory(
        application_key_secret="application-key-for-qb2-xxxxxxxxx"
    )

    # Open a secure, authenticated & asynchronous connection to the sensor
    with blickfeld_qb2.Channel(
            fqdn_or_ip="qb2-xxxxxxxxx",
            token=token_factory
        ) as channel:
        # Request the firmware status asynchronously and await for the response
        response = await blickfeld_qb2.system.services.Firmware(channel).async_get_status()
        # Get the firmware version from the response
        firmware_version = response.status.installed_firmware_info
        # Print the firmware version
        print(firmware_version)

# run coroutine on the event loop
asyncio.run(main())

Output, one field per line:

FirmwareInfo(
    label='HENNING v3.2.4',
    version=Version(major=3, minor=2, patch=4, revision='d1c2d249'),
    allowed_downgrade_version=Version(major=3, patch=11)
)