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() + "a"
      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")  # use `asend` instead of `send`
        assert await sock2.arecv() == b"Hello"  # use `arecv` instead of `recv`

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

Uploaded Source

Built Distribution

zmq_anyio-0.2.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zmq_anyio-0.2.2.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zmq_anyio-0.2.2.tar.gz
Algorithm Hash digest
SHA256 049b6ac837b3bd3ed5cbf18bc625b89c1557cecc76a3a4c7ad647dbe3098e1a6
MD5 65b34881ad0bad77b5df6eaae9f1361d
BLAKE2b-256 39e9668e98dd474332f21e74b86db2759d328ed3abcc8f1a2a0bf858e65ccc5d

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on davidbrochart/zmq-anyio

Attestations:

File details

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

File metadata

  • Download URL: zmq_anyio-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zmq_anyio-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9ff39ab9cec268e0539e27e68371dea8ab271ef85f8fc10e0300771cc9f085
MD5 6d051a4a8f09096e64bdb965762f8644
BLAKE2b-256 d861d1992688563dc8f4530a3f3291a080612e1289368a6d1275261cc69bab32

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on davidbrochart/zmq-anyio

Attestations:

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