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.13.tar.gz (11.9 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.13-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zmq_anyio-0.3.13.tar.gz
  • Upload date:
  • Size: 11.9 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.13.tar.gz
Algorithm Hash digest
SHA256 2c560cfeaf1cb7285a9bda4c490a15b3dedf7749d78652bc6c1ecae09a8581dd
MD5 29e0c69c4bcb2090fa353f43f4c50340
BLAKE2b-256 ce034f1a04e12b931830af2491c93924709ba4498244554227a9313b99364d9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmq_anyio-0.3.13.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.13-py3-none-any.whl.

File metadata

  • Download URL: zmq_anyio-0.3.13-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 80c5478616172aad2a9d4bfd88bf0f1e46969a30c1230df88fe92784632e37f7
MD5 f3d83b7b0e185d108085797fd9c1b118
BLAKE2b-256 3ea9a135029a6d046ee0a036dc6a32a3b7ce63684da65926f7e39f4b8ecbc1f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmq_anyio-0.3.13-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