Asynchronous API for ZMQ using AnyIO
Project description
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.Socketfrom azmq.Socketor from azmq.Context:- Create a blocking ZMQ socket using a
zmq.Context, and pass it to an asynczmq_anyio.Socket:ctx = zmq.Context() sock = ctx.socket(zmq.PAIR) asock = zmq_anyio.Socket(sock)
- Or create an async
zmq_anyio.Socketusing azmq.Context:ctx = zmq.Context() asock = zmq_anyio.Socket(ctx)
- Create a blocking ZMQ socket using a
- Use the
zmq_anyio.Socketwith 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c560cfeaf1cb7285a9bda4c490a15b3dedf7749d78652bc6c1ecae09a8581dd
|
|
| MD5 |
29e0c69c4bcb2090fa353f43f4c50340
|
|
| BLAKE2b-256 |
ce034f1a04e12b931830af2491c93924709ba4498244554227a9313b99364d9c
|
Provenance
The following attestation bundles were made for zmq_anyio-0.3.13.tar.gz:
Publisher:
publish.yml on QuantStack/zmq-anyio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zmq_anyio-0.3.13.tar.gz -
Subject digest:
2c560cfeaf1cb7285a9bda4c490a15b3dedf7749d78652bc6c1ecae09a8581dd - Sigstore transparency entry: 701972454
- Sigstore integration time:
-
Permalink:
QuantStack/zmq-anyio@d753053348e9c0229f6b19bac94963a2dace01cc -
Branch / Tag:
refs/tags/0.3.13 - Owner: https://github.com/QuantStack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d753053348e9c0229f6b19bac94963a2dace01cc -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80c5478616172aad2a9d4bfd88bf0f1e46969a30c1230df88fe92784632e37f7
|
|
| MD5 |
f3d83b7b0e185d108085797fd9c1b118
|
|
| BLAKE2b-256 |
3ea9a135029a6d046ee0a036dc6a32a3b7ce63684da65926f7e39f4b8ecbc1f2
|
Provenance
The following attestation bundles were made for zmq_anyio-0.3.13-py3-none-any.whl:
Publisher:
publish.yml on QuantStack/zmq-anyio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zmq_anyio-0.3.13-py3-none-any.whl -
Subject digest:
80c5478616172aad2a9d4bfd88bf0f1e46969a30c1230df88fe92784632e37f7 - Sigstore transparency entry: 701972456
- Sigstore integration time:
-
Permalink:
QuantStack/zmq-anyio@d753053348e9c0229f6b19bac94963a2dace01cc -
Branch / Tag:
refs/tags/0.3.13 - Owner: https://github.com/QuantStack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d753053348e9c0229f6b19bac94963a2dace01cc -
Trigger Event:
push
-
Statement type: