Quick Start Examples
Below are some examples that highlight these key concepts and show how easy it is to get started with. The more detailed documentation is available in the other sections.
Publish a key/value pair onto Zenoh
# Publish a key/value pair onto Zenoh
with zenoh.open(zenoh.Config()) as session:
session.put("demo/example/hello", "Hello World!")
Subscribe to a set of keys with Zenoh
# Subscribe to a set of keys with Zenoh
with zenoh.open(zenoh.Config()) as session:
with session.declare_subscriber("demo/example/**") as subscriber:
for sample in subscriber:
print(f"{sample.key_expr} => {sample.payload.to_string()}")
Get keys/values from zenoh
# Get keys/values from zenoh
with zenoh.open(zenoh.Config()) as session:
for response in session.get("demo/example/**"):
response = response.ok
print(f"{response.key_expr} => {response.payload.to_string()}")