Skip to main content

pamoja-coap

A CoAP client over UDP with confirmable delivery and observe. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

read the guide documentation API reference

Install

pip install pamoja-coap
from pamoja import coap

This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.

Example

The script the test suite runs, spliced here as it ran.

From bindings/python/guides/coap.py:

import asyncio

from pamoja.coap import CoapClient, Reliability
from pamoja.core import PamojaError


async def main() -> None:
    # CoAP runs over UDP and opens no session, so connecting only binds a local socket.
    # Nothing is listening on the far side here, and for a non-confirmable send nothing
    # needs to be.
    reporter = CoapClient(
        host="127.0.0.1", port=5683, reliability=Reliability.NON_CONFIRMABLE
    )
    await reporter.connect()
    print(f"reporter  connected: {await reporter.is_connected()}")

    # Non-confirmable delivery is at most once: the datagram leaves unacknowledged, which
    # is what a battery-powered node sends when one missed reading costs nothing.
    await reporter.send("sensors/1/temperature", "21.5")
    print("reporter  sent 21.5 and did not wait for an answer")

    # A command is different: it has to arrive. Confirmable delivery retransmits until an
    # acknowledgment comes back. RFC 7252 fixes the defaults at a two-second wait and
    # four retransmissions; both are cut short here so the guide does not sit waiting.
    commander = CoapClient(
        host="127.0.0.1",
        port=5683,
        reliability=Reliability.CONFIRMABLE,
        ack_timeout_ms=20,
        max_retransmits=1,
    )
    await commander.connect()
    try:
        await commander.send("actuators/valve", "open")
        print("commander the valve acknowledged the command")
    except PamojaError as error:
        print(f"commander gave up unacknowledged: {error}")

    await reporter.disconnect()
    print(f"reporter  disconnected: {not await reporter.is_connected()}")


asyncio.run(main())

The same capability in every language

Language Package Reference
Rust pamoja-coap reference, docs.rs, install
TypeScript @pamoja/coap reference, install
Python pamoja-coap reference, install
C# Pamoja.Coap reference, install

Documentation

License

MIT

Release files for pamoja-coap 0.1.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pamoja-coap 0.1.18
File Size Uploaded
pamoja_coap-0.1.18.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-coap 0.1.18
File Interpreter ABI Platform
pamoja_coap-0.1.18-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / pamoja_coap-0.1.18.tar.gz

Download URL pamoja_coap-0.1.18.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
29494b6eeae6ed400ed86673fbff6f6ca31575125298ac0fce2a0bfc3277ce12
BLAKE2b-256 checksum
How to use checksums
50c411ad0e4ef872291ea21bc2c98863bc425329d0ab4717e0b9c8447543f11c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pamoja_coap-0.1.18-py3-none-any.whl

Download URL pamoja_coap-0.1.18-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c61a6b8c4c16a8e4119a90bb6cb9f2bb315708a61cd6fc8a2c7fa6b11f6dbc8d
BLAKE2b-256 checksum
How to use checksums
724aa1182ddd27cca4540c8ae693ad325f02d8bf98aac23fb5daf5d122c6990b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.18 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page