Skip to content

Hello World

We are going to send the message "Hello World" from one node to another, i.e., peer-to-peer, using Python.

In this very introductory Hello_World Quick Start, we focus on you understanding how to run a script and to get a feeling for the effects of hyveOS. If you want a complete walkthrough from developing the asynchronous application code of the Hello_World example to correct dockerizing of the application and pushing it to your Container registry—before deploying it on the node and running—you can go through the tutorial (end-to-end) for Hello World.

Let’s start this very simple demonstration of peer-to-peer robot communication.

Preparation

Prepare two nodes Node 0 and Node 1 with Debian running on each. Make sure that hyveOS is installed or updated to the latest version.

Make sure that Docker is installed on the nodes.

Pull the Docker image

We have already written the Hello_World code. We have dockerized it. You can find the built image hyveos-hello_world in P2P Industries’ GitHub Container Registry.

Pull it directly onto each node with this command:

Terminal window
docker pull ghcr.io/p2p-industries/hyveos-hello_world:latest

What code will be running?

The whole code is seen in the collapsed block. It will run on each node independently. If you want to go through it step-by-step, check out the full Hello_World tutorial.

main.py
import asyncio
from hyveos_sdk import Connection
async def wait_for_peers(discovery):
await asyncio.sleep(2)
async for event in discovery.discovery_events():
if event is not None:
print(f"Discovered a peer: {event}")
break
async def node(topic):
print("--- APPLICATION SCRIPT is RUNNING ---")
async with Connection() as connection:
discovery = connection.get_discovery_service()
gossip_sub = connection.get_gossip_sub_service()
own_id = await discovery.get_own_id()
print(f"Node {own_id} has started.")
await wait_for_peers(discovery)
stream = await gossip_sub.subscribe(topic)
await asyncio.sleep(10)
message = f"Hello from {own_id}"
await gossip_sub.publish(message, topic)
async for msg in stream:
if msg != message:
print(f"Node {own_id} received: {msg}")
break
async def main():
topic = "greetings"
await node(topic)
if __name__ == "__main__":
asyncio.run(main())

What does the main.py do?

Node 0 will discover Node 1 and vice versa. Once they have found each other, they both subscribe to the topic = greetings. Everyone subscribed to topic will receive all the messages someone else sends into the topic—our networking and decentralization components take care of that.
Then, both send the message Hello from <own_node_id> into the greetings, and both nodes will receive a message of the form Hello from <other_node_id> and print it.

Run Hello_World

Use our Command Line Interface to build the image and run it on each node.

Terminal window
<command_1>
<command_2>

Output

You should see an output of the following form on the nodes:

Terminal window
--- APPLICATION SCRIPT is RUNNING ---
Node 12D3KooWJhQGSacp6P54MV1ydF7jfhdS84PUSsFsASz5R5Yx3WTc has started.
Discovered a peer: init {
peers {
peer_id: "12D3KooWGBs4KCjkDHbF5Kb8LRd4A1511uSKEKuvNd13nqWqTRKU"
}
}
Node 12D3KooWJhQGSacp6P54MV1ydF7jfhdS84PUSsFsASz5R5Yx3WTc received: propagation_source {
peer_id: "12D3KooWGBs4KCjkDHbF5Kb8LRd4A1511uSKEKuvNd13nqWqTRKU"
}
source {
peer_id: "12D3KooWGBs4KCjkDHbF5Kb8LRd4A1511uSKEKuvNd13nqWqTRKU"
}
msg {
data {
data: "Hello from 12D3KooWGBs4KCjkDHbF5Kb8LRd4A1511uSKEKuvNd13nqWqTRKU"
}
topic {
topic: "script/greetings"
}
}
msg_id {
id: "12D3KooWGBs4KCjkDHbF5Kb8LRd4A1511uSKEKuvNd13nqWqTRKU1733756699027580799"
}

That’s it! You have successfully used hyveOS to send a message from Node 1 to Node 0 and vice versa.


© 2025 P2P Industries. This documentation is licensed under the MIT License.
Cookie Policy    Privacy Policy