Skip to main content

Networking made simply using nng

Project description

This is pynng.

MIT License PyPI Version Build succeeding Wheels building docs

Ergonomic bindings for nanomsg next generation (nng), in Python. pynng provides a nice interface on top of the full power of nng. nng, and therefore pynng, make it easy to communicate between processes on a single computer or computers across a network. This library is compatible with Python ≥ 3.5. nng is the rewriting of Nanomsg, which is the spiritual successor to ZeroMQ.


Provide a Pythonic, works-out-of-the box library on Windows and Unix-y platforms. Like nng itself, the license is MIT, so it can be used without restriction.


On Windows, MacOS, and Linux, the usual

pip3 install pynng

should suffice. Note that on 32-bit Linux and on macOS no binary distributions are available, so CMake is also required.

Building from the GitHub repo works as well, natch:

git clone
cd pynng
pip3 install -e .

(If you want to run tests, you also need to pip3 install trio curio pytest pytest-asyncio pytest-trio pytest-curio, then just run pytest test.)

pynng might work on the BSDs as well. Who knows!

Using pynng

Using pynng is easy peasy:

from pynng import Pair0

s1 = Pair0()
s2 = Pair0()
s1.send(b'Well hello there')

Since pynng sockets support setting most parameters in the socket's __init__ method and is a context manager, the above code can be written much shorter:

from pynng import Pair0

with Pair0(listen='tcp://') as s1, \
        Pair0(dial='tcp://') as s2:
    s1.send(b'Well hello there')

Using pynng with an async framework

Asynchronous sending also works with

curio, trio and asyncio. Here is an example using trio:

import pynng
import trio

async def send_and_recv(sender, receiver, message):
    await sender.asend(message)
    return await receiver.arecv()

with pynng.Pair0(listen='tcp://') as s1, \
        pynng.Pair0(dial='tcp://') as s2:
    received =, s1, s2, b'hello there old pal!')
    assert received == b'hello there old pal!'

Many other protocols are available as well:

  • Pair0: one-to-one, bidirectional communication.
  • Pair1: one-to-one, bidirectional communication, but also supporting polyamorous sockets
  • Pub0, Sub0: publish/subscribe sockets.
  • Surveyor0, Respondent0: Broadcast a survey to respondents, e.g. to find out what services are available.
  • Req0, Rep0: request/response pattern.
  • Push0, Pull0: Aggregate messages from multiple sources and load balance among many destinations.


Some examples (okay, just two examples) are available in the examples directory.

Git Branch Policy

The only stable branch is master. There will never be a git push -f on master. On the other hand, all other branches are not considered stable; they may be deleted, rebased, force-pushed, and any other manner of funky business.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynng-0.7.2.tar.gz (2.5 MB view hashes)

Uploaded source

Built Distributions

pynng-0.7.2-pp39-pypy39_pp73-win_amd64.whl (378.7 kB view hashes)

Uploaded pp39

pynng-0.7.2-pp38-pypy38_pp73-win_amd64.whl (378.7 kB view hashes)

Uploaded pp38

pynng-0.7.2-pp37-pypy37_pp73-win_amd64.whl (378.7 kB view hashes)

Uploaded pp37

pynng-0.7.2-cp311-cp311-win_amd64.whl (424.7 kB view hashes)

Uploaded cp311

pynng-0.7.2-cp311-cp311-win32.whl (347.7 kB view hashes)

Uploaded cp311

pynng-0.7.2-cp311-cp311-musllinux_1_1_i686.whl (860.7 kB view hashes)

Uploaded cp311

pynng-0.7.2-cp310-cp310-win_amd64.whl (424.7 kB view hashes)

Uploaded cp310

pynng-0.7.2-cp310-cp310-win32.whl (347.7 kB view hashes)

Uploaded cp310

pynng-0.7.2-cp310-cp310-musllinux_1_1_i686.whl (860.6 kB view hashes)

Uploaded cp310

pynng-0.7.2-cp39-cp39-win_amd64.whl (424.7 kB view hashes)

Uploaded cp39

pynng-0.7.2-cp39-cp39-win32.whl (347.7 kB view hashes)

Uploaded cp39

pynng-0.7.2-cp39-cp39-musllinux_1_1_i686.whl (860.7 kB view hashes)

Uploaded cp39

pynng-0.7.2-cp38-cp38-win_amd64.whl (424.7 kB view hashes)

Uploaded cp38

pynng-0.7.2-cp38-cp38-win32.whl (347.7 kB view hashes)

Uploaded cp38

pynng-0.7.2-cp38-cp38-musllinux_1_1_i686.whl (861.0 kB view hashes)

Uploaded cp38

pynng-0.7.2-cp37-cp37m-win_amd64.whl (424.7 kB view hashes)

Uploaded cp37

pynng-0.7.2-cp37-cp37m-win32.whl (348.1 kB view hashes)

Uploaded cp37

pynng-0.7.2-cp37-cp37m-musllinux_1_1_i686.whl (859.5 kB view hashes)

Uploaded cp37

pynng-0.7.2-cp36-cp36m-win_amd64.whl (428.3 kB view hashes)

Uploaded cp36

pynng-0.7.2-cp36-cp36m-win32.whl (349.8 kB view hashes)

Uploaded cp36

pynng-0.7.2-cp36-cp36m-musllinux_1_1_i686.whl (859.5 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page