Skip to main content

Astarte message hub protocol buffers for Python

Project description

Astarte message hub protocol buffers for Python

This module provides access to the Astarte message hub protocol buffers through a Python API.

Basic usage

Use pip to install the astarte-message-hub-proto package.

Then include and use it in your sources as follows:

from datetime import datetime, timezone
import grpc

from google.protobuf.timestamp_pb2 import Timestamp

from astarteplatform.msghub.message_hub_service_pb2_grpc import MessageHubStub
from astarteplatform.msghub.node_pb2 import Node
from astarteplatform.msghub.astarte_message_pb2 import AstarteMessage
from astarteplatform.msghub.astarte_type_pb2 import AstarteDataType, AstarteDataTypeIndividual

grpc_channel = grpc.insecure_channel("server address")
message_hub_stub = MessageHubStub(grpc_channel)

message_hub_node = Node(uuid="node uuid", interfaces_json=[b"interface 1 bin", b"interface 2 bin"])
message_hub_stream = message_hub_stub.Attach(message_hub_node)

# Transmit a very simple message
protobuf_value = AstarteDataType(astarte_individual=AstarteDataTypeIndividual(astarte_double=42.1))

protobuf_timestamp = Timestamp()
protobuf_timestamp.FromDatetime(datetime.now(tz=timezone.utc))

msg = AstarteMessage(
    'interface_name'="interface name",
    'path'="path",
    'timestamp'=protobuf_timestamp,
    'astarte_data'=protobuf_value)
message_hub_stub.Send(msg)

# Never ending receive loop
for astarte_message in message_hub_stream:
    # Parse astarte_message (AstarteMessage) as you see fit.
    print(astarte_message.interface_name)
    print(astarte_message.path)
    print(astarte_message.WhichOneof("payload"))

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

astarte_message_hub_proto-0.10.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

astarte_message_hub_proto-0.10.1-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file astarte_message_hub_proto-0.10.1.tar.gz.

File metadata

File hashes

Hashes for astarte_message_hub_proto-0.10.1.tar.gz
Algorithm Hash digest
SHA256 8fc76c9ba6937d1966ed5c159961df623b8ddae561b8f71e1fb89a66ca35f36d
MD5 2468b5305d151195d6cd976bd0ae6085
BLAKE2b-256 3ad40eaf6a5b6538b00c4a1108d383aabdb2801389d4f4258ea06c7f9449cf03

See more details on using hashes here.

Provenance

The following attestation bundles were made for astarte_message_hub_proto-0.10.1.tar.gz:

Publisher: python-publish.yaml on astarte-platform/astarte-message-hub-proto

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file astarte_message_hub_proto-0.10.1-py3-none-any.whl.

File metadata

File hashes

Hashes for astarte_message_hub_proto-0.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b28b8016c32b8d4d1df8b0c34fd1995f834bb91a930b9c8e3ae6679935a20c3
MD5 9f60191e84dba7a54bca2d1bab910110
BLAKE2b-256 7ce97cbbb67e79e29facc77dfb13ba94d1e909787507ffb73198c1ed36c577be

See more details on using hashes here.

Provenance

The following attestation bundles were made for astarte_message_hub_proto-0.10.1-py3-none-any.whl:

Publisher: python-publish.yaml on astarte-platform/astarte-message-hub-proto

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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