This is Pynng’s Documentation.¶
pynng is Python bindings to Nanomsg Next Generation (nng). It provides a
nice Pythonic interface to the nng library. The goal is that pynng’s interface
feels natural enough to use that you don’t think of it as a wrapper, while
still exposing the power of the underlying library. It is installable with
pip on all major platforms (Linux, Windows, macOS). It has first class support
for Trio and
asyncio, in addition to being able to be used
- There are a few communication patterns that are implemented over and over and over and over and over again. The wheel is continuously reinvented, but no implementations are compatible with each other.
- Not only is the wheel continuosly reinvented, it is reinvented for every combination of transport and protocol. A transport is how data gets from one place to another; things like TCP/IP, HTTP, Unix sockets, carrier pigeons. A protocol is the way that both sides have agreed to communicate with each other (some protocols are ad-hoc, and some are more formal).
The scalability protocols are the basic tools you need to build a distributed system. The following protocols are available:
- pair - simple one-to-one communication. (
- request/response - I ask, you answer. (
- pub/sub - subscribers are notified of topics they are interested in.
- pipeline, aka push/pull - load balancing.
- survey - query the state of multiple applications.
- bus - messages are sent to all connected sockets (
The following transports are available:
- inproc: communication within a single process.
- ipc: communication across processes on a single machine.
- tcp: communication over networks via tcp.
- ws: communication over networks with websockets. (Probably only useful if one end is on a browser.)
- carrier pigeons: communication via World War 1-style carrier pigeons. The latency is pretty high on this one.
These protocols are language-agnostic, and implementations exist for many languages.
If you need two processes to talk to each other—either locally or remotely—you should be using the scalability protocols. You never need to open another socket again.
Okay, that was a little hyperbolic. But give pynng a chance; you might like it.
On Linux, Windows, and macOS, a quick
pip3 install pynng
should do the trick. pynng works on Python 3.5+.