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", interface_jsons=[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
Built Distribution
Close
Hashes for astarte_message_hub_proto-0.6.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 182f044f47215f596799f74931c52ba800a2cf38a08279483bf768f747e09933 |
|
MD5 | 09a373abe9e4a1b40e2e36be85fb158e |
|
BLAKE2b-256 | fd5a5b1fad8f8ddc06c413e69a52751c37902e9c3a090ceeb9bcb6168761b33f |
Close
Hashes for astarte_message_hub_proto-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 224a81522f6b86907f3a9e3900e7040f9327a2d1357a099a1bf9cf48d44f136f |
|
MD5 | 2e88b85ceab591b10578b002c3b33f21 |
|
BLAKE2b-256 | 35641a8c09b0783efd1895f50d996e08b29180377ea3ef8ae243b3c62f2b9e86 |