Skip to main content

Networking made simply using nng

Project description

This is pynng.

MIT License PyPI Version Linux Status Windows Status 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.

Goals

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.

Installation

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 https://github.com/codypiersall/pynng
cd pynng
pip3 install -e .

(If you want to run tests, you also need to pip3 install pytest and pip3 install trio, then just run pytest.)

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

Using pynng

Using pynng is easy peasy:

from pynng import Pair0

s1 = Pair0()
s1.listen('tcp://127.0.0.1:54321')
s2 = Pair0()
s2.dial('tcp://127.0.0.1:54321')
s1.send(b'Well hello there')
print(s2.recv())
s1.close()
s2.close()

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://127.0.0.1:54321') as s1, \
        Pair0(dial='tcp://127.0.0.1:54321') as s2:
    s1.send(b'Well hello there')
    print(s2.recv())

Using pynng with an async framework

Asynchronous sending also works with

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://127.0.0.1:54321') as s1, \
        pynng.Pair0(dial='tcp://127.0.0.1:54321') as s2:
    received = trio.run(send_and_recv, 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.

Feel free to check out the documentation, which is currently a work in progress.

Examples

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.

TODO

  • More docs. Most of the public API has docstrings, but hosted documentation at readthedocs will happen one day.

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.4.0.tar.gz (607.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pynng-0.4.0-cp37-cp37m-win_amd64.whl (192.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

pynng-0.4.0-cp37-cp37m-win32.whl (181.7 kB view details)

Uploaded CPython 3.7mWindows x86

pynng-0.4.0-cp37-cp37m-manylinux1_x86_64.whl (311.6 kB view details)

Uploaded CPython 3.7m

pynng-0.4.0-cp36-cp36m-win_amd64.whl (192.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

pynng-0.4.0-cp36-cp36m-win32.whl (181.7 kB view details)

Uploaded CPython 3.6mWindows x86

pynng-0.4.0-cp36-cp36m-manylinux1_x86_64.whl (311.6 kB view details)

Uploaded CPython 3.6m

pynng-0.4.0-cp35-cp35m-win_amd64.whl (192.5 kB view details)

Uploaded CPython 3.5mWindows x86-64

pynng-0.4.0-cp35-cp35m-win32.whl (181.7 kB view details)

Uploaded CPython 3.5mWindows x86

pynng-0.4.0-cp35-cp35m-manylinux1_x86_64.whl (311.6 kB view details)

Uploaded CPython 3.5m

File details

Details for the file pynng-0.4.0.tar.gz.

File metadata

  • Download URL: pynng-0.4.0.tar.gz
  • Upload date:
  • Size: 607.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6c736ee88ba12c39c8dd7cb10c67cae35c088a8a658e7c73f3e8c15c1b904118
MD5 39f7f68993bfa6d2a85602d832ac1ac0
BLAKE2b-256 1bfb23266f32a8dfa1c86991b6315577e95b803061de154725a82e5ff6f800d4

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 192.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0ea6ed565d11352fda6a499ccd170ef812b468229c68390d864d06da43307edc
MD5 41eaec524342e8c5462ef504a8844371
BLAKE2b-256 e84dfb14a68c63e34a8bf64208eaff47d33721290ea6d4d77c30ad4387eda0bd

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: pynng-0.4.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 181.7 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 e157174385915ffc3e90af0ea2203df8a092eba7be44616d076e6c06ba6848d0
MD5 a899d34af4926dcaab2174022ace8edc
BLAKE2b-256 3c3ef8878ac2979d39cdcc48501e74dc4d04e826e43e469ec862a328bcf94028

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 311.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cec03829a34f22516f563df42414614e7735d28c8018b41352f8a6faae4be8fa
MD5 784968488e8532c86a8b96510051d052
BLAKE2b-256 e359dbff1b76b23319909cde1ba03e08825413bdfd789734efd1fd4ddf374d9a

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 192.5 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f4971661369cd073d152efa6141ebb307ad4aac50cffa8292bd242727fffaf5e
MD5 a1b6da64af0a2ce836b42de52d8a1e48
BLAKE2b-256 95331a50756ad3dbaea507a972e8cf0b223070dc810025fbfc08be1a06fa3dd9

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: pynng-0.4.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 181.7 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 e01a1e66211cefb94f6ee69b587565ffac174a4c0593b16cfefa1e968fca6777
MD5 07865e6d9a5d8c04ca7b76fcc7e4ea79
BLAKE2b-256 fb518a7181a69e2537d02518f444dcd3fd9d064971e1f34301af267295540a89

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 311.6 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c9d099ed84f158b64321f63db390043b10b7475406933f82a4ac9fe8efd9cbb1
MD5 42a3990711562995ccbcad1f3c30821b
BLAKE2b-256 4b63ba1ca36cdbb036c0ce229c30bd64454accb745f0b45bcbbce6e49235a9c7

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 192.5 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 be73bde665b1c3d64133233b2e058af5cae7505b667434bbac0c56a6a7d2c788
MD5 dc1792f3b1e460a55c7a9fdb257554dc
BLAKE2b-256 06a450681d9ac3e9459029d212325434d1a80e737a404d5e147e251d04880020

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp35-cp35m-win32.whl.

File metadata

  • Download URL: pynng-0.4.0-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 181.7 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 f8a6867190e6a860762b0d1f7abe943390da9a43f9fe0b657563cbdca009f8ac
MD5 bfb72c182a3bd39faf08c47b431a2ca7
BLAKE2b-256 e332fb07dfad19818ac116ce76f4d23201dfd62f103f28bf14892faa14934238

See more details on using hashes here.

File details

Details for the file pynng-0.4.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynng-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 311.6 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for pynng-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d8872f54946c9eb8d6896893795c5a18e5e2c0975ed86ddd9cf914e8a6ef603c
MD5 2e81a7fb79778612f75e972b7893988d
BLAKE2b-256 ce3dbf9f3dc2488218f142eeec90ac498018dff2e2a5aea2c26575bba294a717

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page