Skip to main content

Python bindings for the OUCH protocol

Project description

This package is python extension module for rust crate ouch_connect_nonblocking

Installation & Test

  • pytest expects ouch_connect source to be checked out from github. Test files are located in ./bindings/python/tests directory.
micromamba create --name ouch_pypi_env --yes python &&
micromamba run --name ouch_pypi_env pip install "ouch-connect[test]>=5.0,<5.1" &&
micromamba run --name ouch_pypi_env pytest

Basic Usage Example

import logging
from time import sleep
from ouch_connect import CltAuto, SvcAuto
from links_connect.callbacks import LoggerCallback, DecoratorDriver, on_recv, on_sent, MemoryStoreCallback


logging.basicConfig(format="%(asctime)-15s [%(threadName)10s|%(levelname)8s] %(message)s \t%(filename)s:%(lineno)d")
logging.getLogger().setLevel(logging.INFO)
log = logging.getLogger(__name__)
addr = "127.0.0.1:8080"

class SimulatorExample(DecoratorDriver):
    @on_recv({"Dbg": {}})
    def on_dbg(self, con_id, msg):
        self.sender.send({"Dbg": {"text": "Hello from Simulator"}})

    @on_recv({})
    def on_all_recv(self, con_id, msg):
        pass

    @on_sent({})
    def on_all_sent(self, con_id, msg):
        pass

store = MemoryStoreCallback()
clt_clbk = LoggerCallback(sent_level=logging.NOTSET) + store
svc_clbk = SimulatorExample() + store
with (
    SvcAuto(addr, svc_clbk, **dict(name="svc-ouch")) as svc,
    CltAuto(addr, clt_clbk, **dict(name="clt-ouch")) as clt,
):
    assert clt.is_connected() and svc.is_connected()

    log.info(f"svc: {svc}")
    log.info(f"clt: {clt}")

    clt.send({"Dbg": {"text": "Hello from Clt"}})

    found = store.find_recv(name="svc-ouch", filter={"Dbg":{}})
    assert found is not None and found.msg["Dbg"]["text"] == "Hello from Clt"
    log.info(f"found: {found}")

    found = store.find_recv(name="clt-ouch", filter={"Dbg":{}})
    assert found is not None and found.msg["Dbg"]["text"] == "Hello from Simulator"
    log.info(f"found: {found}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

ouch_connect-5.0.1-cp310-abi3-win_amd64.whl (680.9 kB view hashes)

Uploaded CPython 3.10+ Windows x86-64

ouch_connect-5.0.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ x86-64

ouch_connect-5.0.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.0 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ s390x

ouch_connect-5.0.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

ouch_connect-5.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

ouch_connect-5.0.1-cp310-abi3-macosx_11_0_arm64.whl (863.4 kB view hashes)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

ouch_connect-5.0.1-cp310-abi3-macosx_10_12_x86_64.whl (857.2 kB view hashes)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page