Skip to main content

ZeroMQ sockets integrated with the AsyncIO event loop

Project description

Zantedeschia is an experimental alternative integration between asyncio and ZeroMQ sockets.

I started trying to use aiozmq, but I objected to some of the design decisions. I borrowed ideas from that code, but did a few things differently:

  1. aiozmq is built around asyncio’s protocol and transport APIs, which I find hard to use; even the simplest examples involve subclassing ZmqProtocol. Zantedeschia uses a single AsyncZMQSocket wrapper class, with simple semantics.

  2. Zantedeschia does not include an RPC framework.

  3. Zantedeschia expects the user to create and connect ZMQ sockets using PyZMQ, then wrap them in an AsyncZMQSocket object.

Zantedeschia is a genus of flowers. Asyncio itself was originally codenamed ‘tulip’, and a tradition developed of naming asyncio libraries after flowers.

Use this at your own risk. MinRK, the author of PyZMQ, told me that I definitely shouldn’t rely on the ZMQ file descriptors for an event loop, but I’m doing exactly that.

Ping server example:

import asyncio, zmq, zantedeschia

ctx = zmq.Context()
s = ctx.socket(zmq.REP)
s.bind('tcp://127.0.0.1:8123')
async_sock = zantedeschia.AsyncZMQSocket(s)

def pong():
    while True:
        msg_parts = yield from async_sock.recv_multipart()
        yield from async_sock.send_multipart(msg_parts)

asyncio.get_event_loop().run_until_complete(pong())

Using the on_recv API instead:

import asyncio, zmq, zantedeschia

ctx = zmq.Context()
s = ctx.socket(zmq.REP)
s.bind('tcp://127.0.0.1:8123')
async_sock = zantedeschia.AsyncZMQSocket(s)

@async_sock.on_recv
def pong(msg_parts):
    async_sock.send_multipart(msg_parts)

asyncio.get_event_loop().run_forever()

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

Zantedeschia-0.1.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file Zantedeschia-0.1.tar.gz.

File metadata

  • Download URL: Zantedeschia-0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Zantedeschia-0.1.tar.gz
Algorithm Hash digest
SHA256 48104800c103189d4f45f8a18f353791a723ab797967a0be6afba3c75c1309d8
MD5 e0d02a1d681c9e5a1cb558ec44cd840b
BLAKE2b-256 ba3b7ce39b5a9ac82e3e441eff56bb1898479c29d7455d9d30c86ac98256b364

See more details on using hashes here.

Supported by

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