Skip to main content

COMPAS Event Extensions: adds event-based communication infrastructure to the COMPAS framework.

Project description

COMPAS EVE

Event-based communication for the COMPAS framework.

>>> import compas_eve as eve
>>> pub = eve.Publisher("/hello_world")
>>> sub = eve.EchoSubscriber("/hello_world")
>>> sub.subscribe()
>>> for i in range(10):
...    pub.publish(dict(text=f"Hello World {i}"))

It is extremely easy to send messages around. COMPAS EVE supports different transport mechanisms to send messages between different threads, processes, computers, etc.

Installation

Install using pip:

    pip install compas_eve

Or using conda:

    conda install compas_eve

Supported features

  • Publisher/subscriber communication model (N-to-N communication)
  • In-process events
  • MQTT support
  • Extensible codec system for message serialization (JSON, Protocol Buffers)

Examples

In-process events

The simplest option is to use in-process events. This works for simple applications and allows to communicate between threads.

import compas_eve as eve

pub = eve.Publisher("/hello_world")
sub = eve.EchoSubscriber("/hello_world")
sub.subscribe()

for i in range(10):
    pub.publish(dict(text=f"Hello World {i}"))

MQTT

MQTT is a protocol that allows to send messages between different systems/computers. Using MQTT is very simple as well:

import compas_eve as eve
from compas_eve.mqtt import MqttTransport

tx = MqttTransport("broker.hivemq.com")
eve.set_default_transport(tx)

pub = eve.Publisher("/hello_world")
sub = eve.EchoSubscriber("/hello_world")
sub.subscribe()

for i in range(10):
    pub.publish(dict(text=f"Hello World {i}"))

This example shows how to send and receive from a single script, but running publishers and subscribers on different scripts, different processes, or even different computers will work the exact same way.

Using different codecs

By default, COMPAS EVE uses JSON for message serialization. However, you can use different codecs for more efficient serialization:

import compas_eve as eve
from compas_eve import JsonMessageCodec
from compas_eve.codecs import ProtobufMessageCodec
from compas_eve.mqtt import MqttTransport

# Use JSON codec (default)
json_codec = JsonMessageCodec()
tx = MqttTransport("broker.hivemq.com", codec=json_codec)

# Or use Protocol Buffers for binary serialization (requires compas_pb)
pb_codec = ProtobufMessageCodec()
tx = MqttTransport("broker.hivemq.com", codec=pb_codec)

Usage from Rhinoceros 3D

It is possible to use the same code from within Rhino/Grasshopper.

To install compas_eve, use the the syntax # r: compas_eve at the top of any Python 3.x script in Rhino/Grasshopper.

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

compas_eve-2.1.1.tar.gz (40.6 kB view details)

Uploaded Source

Built Distribution

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

compas_eve-2.1.1-py2.py3-none-any.whl (42.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file compas_eve-2.1.1.tar.gz.

File metadata

  • Download URL: compas_eve-2.1.1.tar.gz
  • Upload date:
  • Size: 40.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for compas_eve-2.1.1.tar.gz
Algorithm Hash digest
SHA256 110f6d04a38e21a9fe7f904b55899dbbdd0cca167e8b200ed9e2dca3b6ff1299
MD5 d18e15db4738cdd6b086468c7772d591
BLAKE2b-256 436dbc8acc4ea1a48130003a09a1c16e361d64a6741e74dade99482399a99528

See more details on using hashes here.

File details

Details for the file compas_eve-2.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: compas_eve-2.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for compas_eve-2.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 84a24f77ed0d4c71ffc7c3154acd7cdd8fe3111dee7b881e2c0495ca33e7162c
MD5 6a7a8a37bb9d135d1b56e4a370eedd7a
BLAKE2b-256 1280b27d627f63acd3b2984656929d5e7b7440f67ab483b9edf4cec58af2df2d

See more details on using hashes here.

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