{"library":"pynng","title":"Pynng","description":"Pynng is a Python binding for the nng (nanomsg-next-generation) C library, providing lightweight, high-performance messaging patterns for network communication. It supports both synchronous and asynchronous (asyncio) operations, making it suitable for a wide range of network applications. The current version is 0.9.0, and it generally follows a moderate release cadence, with updates often introducing significant features or improvements.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pynng"],"cli":null},"imports":["import pynng","from pynng import Rep0, Req0"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pynng\nimport asyncio\n\nasync def main():\n    addr = \"tcp://127.0.0.1:5555\"\n\n    async def server():\n        \"\"\"Simple Request-Reply server.\"\"\"\n        with pynng.Rep0() as rep_sock:\n            rep_sock.listen(addr)\n            print(\"Server: Listening...\")\n            # Receive and immediately reply, then close after 2 messages\n            for _ in range(2):\n                msg = await rep_sock.arecv()\n                print(f\"Server: Received '{msg.decode()}'\")\n                await rep_sock.asend(b\"PONG\")\n            print(\"Server: Done.\")\n\n    async def client():\n        \"\"\"Simple Request-Reply client.\"\"\"\n        await asyncio.sleep(0.1) # Give server a moment to start\n        with pynng.Req0() as req_sock:\n            req_sock.dial(addr)\n            print(\"Client: Dialed.\")\n            for i in range(2):\n                await req_sock.asend(f\"PING {i}\".encode())\n                reply = await req_sock.arecv()\n                print(f\"Client: Received '{reply.decode()}'\")\n            print(\"Client: Done.\")\n\n    await asyncio.gather(server(), client())\n\nif __name__ == \"__main__\":\n    # This example demonstrates async usage, which is common in modern pynng applications.\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates a basic asynchronous request-reply (REQ/REP) pattern using pynng. It sets up a minimal server that listens for messages and replies, and a client that sends messages and receives replies. Both are run concurrently using asyncio.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}