{"id":20908,"library":"aiocoap","title":"aiocoap","description":"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.","status":"active","version":"0.4.17","language":"python","source_language":"en","source_url":"https://github.com/chrysn/aiocoap","tags":["coap","iot","async","protocol","python3"],"install":[{"cmd":"pip install aiocoap","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"In older versions (pre-0.4), the module path was different. Use top-level import.","wrong":"from aiocoap.message import Message","symbol":"Message","correct":"from aiocoap import Message"},{"note":"Context moved to top-level in 0.4. Old import path breaks.","wrong":"from aiocoap.protocol import Context","symbol":"Context","correct":"from aiocoap import Context"},{"note":"In 0.4, request codes are directly under aiocoap.","wrong":"from aiocoap.numbers import GET","symbol":"GET","correct":"from aiocoap import GET"},{"symbol":"POST","correct":"from aiocoap import POST"},{"symbol":"PUT","correct":"from aiocoap import PUT"},{"symbol":"DELETE","correct":"from aiocoap import DELETE"}],"quickstart":{"code":"import asyncio\nfrom aiocoap import *\n\nasync def main():\n    context = await Context.create_client_context()\n    request = Message(code=GET, uri='coap://coap.me/.well-known/core')\n    response = await context.request(request).response\n    print(response.payload.decode())\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"Minimal CoAP client that fetches the resource discovery from coap.me."},"warnings":[{"fix":"Update imports to use top-level names and use the new Context API.","message":"aiocoap 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.","severity":"breaking","affected_versions":"<0.4"},{"fix":"Use 'async with Context.create_client_context() as context:' to ensure proper resource cleanup.","message":"The 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.","severity":"deprecated","affected_versions":">=0.4"},{"fix":"Always verify the URI scheme is correct for CoAP.","message":"CoAP URIs must start with 'coap://' or 'coaps://' (for DTLS). Using 'http://' will cause a silent malformed URI error.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'from aiocoap import BlockOption' and set appropriate block options on the request.","message":"When sending large payloads (> 64 KiB), aiocoap requires block-wise transfer (Block1/Block2). Without explicit block options, the library may fail with a MessageTooLong error.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to 'from aiocoap import Message'.","cause":"Old import path from aiocoap.message import Message used in code written for aiocoap <0.4.","error":"ImportError: cannot import name 'Message' from 'aiocoap'"},{"fix":"Install aiocoap with DTLS extras: pip install aiocoap[dtls] or install tinydtls manually.","cause":"Trying to use coaps:// URIs without installing DTLS support.","error":"aiocoap.error.FeatureNotImplementedError: DTLS support requires module 'tinydtls'"},{"fix":"Use asyncio.run(main()) or Context.create_client_context() as async context manager.","cause":"Using deprecated loop-based pattern in Python 3.10+ where asyncio.get_event_loop() may return a different loop type.","error":"AttributeError: 'EventLoop' object has no attribute 'run_until_complete'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}