Registry / http-networking / aiocoap

aiocoap

JSON →
library0.4.17pypypi✓ verified 88d ago

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.

pip install aiocoap
INSTALL
IMPORT
SIG · AIOCOAP
A
aiocoap
http-networkingpythonv0.4.17
Install
1.7s avg
Import
244ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.262s · 19.5MB
glibc
py 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())
Debug
Known issues
breakingaiocoap 0.4 introduced major API changes: import paths moved from submodules to top-level (e.g., from aiocoap import Message instead of aiocoap.message.Message). Context creation changed: use Context.create_client_context() instead of old patterns asyncio.get_event_loop(). Code written for 0.3.x will not work.
fix
Update imports to use top-level names and use the new Context API.
affects: <0.4
deprecatedThe async context manager pattern (async with Context.create_client_context()) is now preferred over the old loop-based pattern. Old code using loop.run_until_complete may still work but is deprecated.
fix
Use 'async with Context.create_client_context() as context:' to ensure proper resource cleanup.
affects: >=0.4
gotchaCoAP URIs must start with 'coap://' or 'coaps://' (for DTLS). Using 'http://' will cause a silent malformed URI error.
fix
Always verify the URI scheme is correct for CoAP.
affects: all
gotchaWhen sending large payloads (> 64 KiB), aiocoap requires block-wise transfer (Block1/Block2). Without explicit block options, the library may fail with a MessageTooLong error.
fix
Use 'from aiocoap import BlockOption' and set appropriate block options on the request.
affects: all
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.
fix
Change to 'from aiocoap import Message'.
aiocoap.error.FeatureNotImplementedError: DTLS support requires module 'tinydtls'
Trying to use coaps:// URIs without installing DTLS support.
fix
Install 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.
fix
Use asyncio.run(main()) or Context.create_client_context() as async context manager.
Upgrade
Version history
0.4.17latest on PyPI · released Nov 5, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
67 hits · last 30 days
node
57
Amazon
1
OpenAI (training)
1
Resources
aiocoap — pip install aiocoap · libregistry