Skip to main content

Asynchronous API for ZMQ using AnyIO

Project description

Build Status

zmq-anyio

Asynchronous API for ZMQ using AnyIO.

Usage

zmq_anyio.Socket is a subclass of zmq.Socket. Here is how it must be used:

  • Create a zmq_anyio.Socket from a zmq.Socket or from a zmq.Context:
    • Create a blocking ZMQ socket using a zmq.Context, and pass it to an async zmq_anyio.Socket:
      ctx = zmq.Context()
      sock = ctx.socket(zmq.PAIR)
      asock = zmq_anyio.Socket(sock)
      
    • Or create an async zmq_anyio.Socket using a zmq.Context:
      ctx = zmq.Context()
      asock = zmq_anyio.Socket(ctx)
      
  • Use the zmq_anyio.Socket with an async context manager.
  • Use arecv() for the async API, recv() for the blocking API, etc.
import anyio
import zmq
import zmq_anyio

ctx = zmq.Context()
sock1 = ctx.socket(zmq.PAIR)
port = sock1.bind("tcp://127.0.0.1:1234")
sock2 = ctx.socket(zmq.PAIR)
sock2.connect("tcp://127.0.0.1:1234")

# wrap the `zmq.Socket` with `zmq_anyio.Socket`:
sock1 = zmq_anyio.Socket(sock1)
sock2 = zmq_anyio.Socket(sock2)

async def main():
    async with sock1, sock2:  # use an async context manager
        await sock1.asend(b"Hello").wait()  # use `asend` instead of `send`, and await the `.wait()` method
        sock1.asend(b", World!")  # or don't await it, it's sent in the background
        assert await sock2.arecv().wait() == b"Hello"  # use `arecv` instead of `recv`, and await the `.wait()` method
        future = sock2.arecv()  # or get the future and await it later
        assert await future.wait() == b", World!"

anyio.run(main)

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

zmq_anyio-0.3.14.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

zmq_anyio-0.3.14-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file zmq_anyio-0.3.14.tar.gz.

File metadata

  • Download URL: zmq_anyio-0.3.14.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zmq_anyio-0.3.14.tar.gz
Algorithm Hash digest
SHA256 1ec77999f62f576bacfa020f3aa11491da54d1bed7a77af8505b3add7da2366b
MD5 72226231e961150709e3ec89aa3dd5a6
BLAKE2b-256 b26c9f903c949e7b3aa9fee9492a259807f5ba2061d650822b4c098edc5cf565

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmq_anyio-0.3.14.tar.gz:

Publisher: publish.yml on QuantStack/zmq-anyio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zmq_anyio-0.3.14-py3-none-any.whl.

File metadata

  • Download URL: zmq_anyio-0.3.14-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zmq_anyio-0.3.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5126002e5a5c615e99b750e033e1351da775650aa865d9188e540368520d99a6
MD5 8791962ee055df5878efa6e1220aee9f
BLAKE2b-256 162141d868cdb623b7c92799927aaf7fc8b984c1fbb0525c5a3a7f19a9cb711c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmq_anyio-0.3.14-py3-none-any.whl:

Publisher: publish.yml on QuantStack/zmq-anyio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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