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
Built Distribution
File details
Details for the file astarte_message_hub_proto-0.7.0.tar.gz
.
File metadata
- Download URL: astarte_message_hub_proto-0.7.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5218b760bbac8e1360f67bd2cbf9127379caa9d06c39b1d9f1e97c17082b988 |
|
MD5 | 4b4ad273b20db9d0734d0e5e66c1640e |
|
BLAKE2b-256 | bceb176c790099686837f9955aa46639f03f7f421715429aef5573f7098576fa |
File details
Details for the file astarte_message_hub_proto-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: astarte_message_hub_proto-0.7.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41310d874b2f92870439df8e5bbff9207abb0e32a9893044a4e91097b0516f70 |
|
MD5 | 4cf65859a04a83ab024273501843da15 |
|
BLAKE2b-256 | 43b1a64cc2f27f471a68d75c61d3e77e40c9340608bcfecad5170414db2aaa70 |