libcoapy
libcoapy project enables communication over the CoAP protocol (RFC 7252). The
llapi module provides ctypes-based wrappers for the libcoap
C library. The libcoapy module uses llapi to provide a high-level class interface
to the libcoap functions.
Dependencies:
- libcoap (v4.3.5 or higher is recommended)
- ifaddr (optional, to query all IPs of an interface)
- netifaces (optional alternative to ifaddr)
Status
The llapi module provides a complete interface for the current version of the libcoap library. The high-level API of libcoapy is still missing some parts and might change in the future.
Portability
libcoapy is a pure python module and the underlying libcoap supports several platforms like Linux, Windows, MacOS and Android. However, libcoap (and hence libcoapy) does not support all features on all platforms and with all possible SSL/TLS libraries.
If you want to use libcoapy with asyncio on platforms without epoll, like Windows,
it might be necessary to choose an event loop that supports add_reader(). On
Windows you might need to add this to your code before initializing the loop:
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Provided tools
In the examples folder, this repo provides the following general-purpose tools:
- coap-gui - a small Tkinter-based GUI to interact with a CoAP server
- coarl - a CLI tool that provides a similar interface as curl
Documentation
API documentation: https://anyc.github.io/libcoapy/
Example: client
from libcoapy import *
if len(sys.argv) < 2:
uri_str = "coap://localhost"
else:
uri_str = sys.argv[1]
ctx = CoapContext()
session = ctx.newSession(uri_str)
def rx_cb(session, tx_msg, rx_msg, mid):
print(rx_msg.payload)
session.ctx.stop_loop()
session.sendMessage(path=".well-known/core", response_callback=rx_cb)
ctx.loop()
Example: server
from libcoapy import *
def echo_handler(resource, session, request, query, response):
response.payload = request.payload
def time_handler(resource, session, request, query, response):
import datetime
now = datetime.datetime.now()
response.payload = str(now)
ctx = CoapContext()
ctx.addEndpoint("coap://[::]")
time_rs = CoapResource(ctx, "time")
time_rs.addHandler(time_handler)
ctx.addResource(time_rs)
echo_rs = CoapResource(ctx, "echo")
echo_rs.addHandler(echo_handler)
ctx.addResource(echo_rs)
ctx.loop()
More examples can be found in the examples directory.
Metadata
Release files for libcoapy 2026.11.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| libcoapy-2026.11.26.tar.gz | 39.7 kB | Without provenance | Details for libcoapy-2026.11.26.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libcoapy-2026.11.26-py3-none-any.whl | Python 3 | none | any | Details for libcoapy-2026.11.26-py3-none-any.whl |
Total release size: 81.6 kB
Release files / libcoapy-2026.11.26.tar.gz
| Download URL | libcoapy-2026.11.26.tar.gz |
|---|---|
| Size | 39.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bba34b1bb9fd2b7c6fa8f9a77340c9e8071a23859b6b7f75898ec1af6f9abade
|
|
BLAKE2b-256 checksum How to use checksums |
5034871f4e5676ad6926d11b3637c506ead862c84848cdfc904716f19fe22371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.15
|
Release files / libcoapy-2026.11.26-py3-none-any.whl
| Download URL | libcoapy-2026.11.26-py3-none-any.whl |
|---|---|
| Size | 42.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f517844019ac9cfbcedca32e9c48d8f3d52ae66fe52346f994ac3cf6c4c78f3
|
|
BLAKE2b-256 checksum How to use checksums |
51554348ea8958f1db67c1b1c15f870d176b0310011dc57c2dd09456d012299e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.15
|
Security for libcoapy 2026.11.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.