aiocoap is a Python library for the Constrained Application Protocol (CoAP) as defined in RFC 7252. Current version 0.4.17 supports Python >=3.10. It provides both client and server abstractions with async/await support. Releases are semi-regular, with major version changes introducing breaking API shifts.
Install & Compatibility
Where this runs
tested against v0.4.17 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.262s · 19.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.226s · 20MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Message
✓ from aiocoap import Message
✗ from aiocoap.message import Message
In older versions (pre-0.4), the module path was different. Use top-level import.
Context
✓ from aiocoap import Context
✗ from aiocoap.protocol import Context
Context moved to top-level in 0.4. Old import path breaks.
GET
✓ from aiocoap import GET
✗ from aiocoap.numbers import GET
In 0.4, request codes are directly under aiocoap.
POST
✓ from aiocoap import POST
PUT
✓ from aiocoap import PUT
DELETE
✓ from aiocoap import DELETE
Minimal CoAP client that fetches the resource discovery from coap.me.
import asyncio
from aiocoap import *
async def main():
context = await Context.create_client_context()
request = Message(code=GET, uri='coap://coap.me/.well-known/core')
response = await context.request(request).response
print(response.payload.decode())
if __name__ == "__main__":
asyncio.run(main())
Errors
Common errors & fixes
ImportError: cannot import name 'Message' from 'aiocoap'
Old import path from aiocoap.message import Message used in code written for aiocoap <0.4.
fixChange to 'from aiocoap import Message'.
aiocoap.error.FeatureNotImplementedError: DTLS support requires module 'tinydtls'
Trying to use coaps:// URIs without installing DTLS support.
fixInstall aiocoap with DTLS extras: pip install aiocoap[dtls] or install tinydtls manually.
AttributeError: 'EventLoop' object has no attribute 'run_until_complete'
Using deprecated loop-based pattern in Python 3.10+ where asyncio.get_event_loop() may return a different loop type.
fixUse asyncio.run(main()) or Context.create_client_context() as async context manager.
Audit
Dependencies
No dependency data recorded yet.