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 synchronously.

nng is an implementation of the Scalability Protocols; it is the spiritual successor to ZeroMQ. There are a couple of distributed systems problems that the scalability protocols aim to solve:

  1. 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.
  2. 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. (Pair0, Pair1.)
  • request/response - I ask, you answer. (Req0, Rep0)
  • pub/sub - subscribers are notified of topics they are interested in. (Pub0, Sub0)
  • pipeline, aka push/pull - load balancing. (Push0, Pull0)
  • survey - query the state of multiple applications. (Surveyor0, Respondent0)
  • bus - messages are sent to all connected sockets (Bus0)

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.

This library is available under the MIT License and the source is available on GitHub.

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.

Installing pynng

On Linux, Windows, and macOS, a quick

pip3 install pynng

should do the trick. pynng works on Python 3.5+.

Indices and tables