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.
pip install pynngVerified import paths — ran on the pinned version, not inferred.
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.
Ensure you have a C compiler and development headers installed. On Debian/Ubuntu: `sudo apt-get install build-essential`. On Fedora: `sudo dnf groupinstall "Development Tools"`. On macOS: Install Xcode Command Line Tools (`xcode-select --install`).
For new applications, prefer `asyncio` methods (`asend`, `arecv`, `aconnect`, `aclose`). For existing sync code, ensure you're explicitly using `send`, `recv`, etc., and be mindful of blocking operations in an `asyncio` context.
Always use `with sock.open_context() as ctx:` for managing `nng` contexts, ensuring they are properly closed. Refer to the official `pynng` documentation for advanced context usage patterns.
Install a C compiler and development headers. For Linux (Debian/Ubuntu): `sudo apt-get install build-essential`. For macOS: `xcode-select --install`. For Windows, consider using WSL or Visual Studio Build Tools.
If using `asyncio`, use `await sock.arecv()` and `await sock.asend()`. If explicitly using synchronous operations (less common in modern `pynng` code), ensure you are calling the non-`a` prefixed methods (`sock.recv()`, `sock.send()`).
Ensure your server process is running and actively listening on the specified address and port before the client attempts to dial. Check firewall rules if the server is on a different machine or network.
No dependency data recorded yet.