ZMQ Vision
Serve image models and small local LLMs over ZeroMQ. Run a model in its own process and call it from Python, asyncio, or the CLI. The core install is lightweight. Add PyTorch, TensorFlow, or llama.cpp when you need it.
Quick start · Models · Python API · Design · Benchmarks
Quick start
In a Python 3.10+ virtual environment:
python -m pip install zmq-vision
zmq-vision demo
The demo starts a real localhost TCP server, checks readiness, sends one image from each Python client, and shuts down. It ranks RGB channel intensity, so you can exercise the full transport without model weights or a GPU.
Use zmq-vision demo --json for machine-readable output or zmq-vision doctor to inspect installed runtime versions.
You can also install a wheel from GitHub Releases.
Serve a model
Generate text on CPU
Install the optional backend and download the 105 MB SmolLM2-135M Instruct GGUF. Python 3.12 on Linux or WSL is the tested setup. If pip builds llama.cpp from source, it needs a C/C++ toolchain. See llama-cpp-python installation.
python -m pip install "zmq-vision[llm]>=0.4.0"
curl -fL -o smollm2.gguf \
https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/09816acd5d99df7be770d85ea30822623dab342c/SmolLM2-135M-Instruct-Q4_K_M.gguf
zmq-vision serve --backend llm --model-path smollm2.gguf
In another terminal:
zmq-vision health
zmq-vision generate "Name three uses for a Raspberry Pi." --max-tokens 48
zmq-vision generate "Name three primary colors." --async --json
The server reads a local ChatML-compatible GGUF, uses two CPU threads by default, and returns the answer with prompt and completion token counts. Prompts and inference stay on the serving machine when both ends run on localhost. No API key is required. The base model and quantized weights use Apache 2.0. llama-cpp-python uses MIT.
Classify an image
python -m pip install "zmq-vision[torch]"
zmq-vision serve --backend torch --model mobilenetv2_100 --device cpu
From another terminal, pass any local image:
zmq-vision infer photo.jpg --async --json
For TensorFlow, install zmq-vision[tf] and run zmq-vision serve --backend tf --device cpu. PyTorch uses timm ImageNet-1k models and TensorFlow uses Keras MobileNet. Both download pretrained weights on the first run. Bring your own image model by implementing load_model, preprocess, and predict.
Python API
SyncClient and AsyncClient both support ping(), infer(image), and generate(prompt). Connect to the server running the corresponding backend.
from zmq_inference.client import SyncClient
with SyncClient() as client:
result = client.infer("photo.jpg")
if not result.ok:
raise RuntimeError(result.error)
print(result.predictions[0])
import asyncio
from zmq_inference.client.async_client import AsyncClient
async def main():
async with AsyncClient() as client:
result = await client.generate("What is a message queue?", max_tokens=48)
if not result.ok:
raise RuntimeError(result.error)
print(result.generation.text)
asyncio.run(main())
Both examples use 127.0.0.1:5576. Pass a ClientConfig or CLI --host and --port to connect elsewhere. The zmq_inference import, zmq-inference command alias, and 0.3 image wire format remain supported. Configuration and migration
How it works
flowchart LR
C["CLI · SyncClient · AsyncClient"] <-->|"DEALER / ROUTER · TCP"| R["Socket-owning network thread"]
R --> Q["Bounded admission"]
Q --> W["Model worker"]
W --> M["timm · Keras · llama.cpp · custom"]
W -->|"Completed future"| R
- Backpressure. One thread owns the ROUTER socket. Model workers handle inference off that thread. The server admits at most 16 running or queued requests by default and sends a busy response when full.
- Response correlation. Every response carries a request ID. Clients replace their socket after a timeout or async cancellation, so a late response cannot be mistaken for a later result.
- Lifecycle. Readiness means the model has loaded and the socket has bound. Shutdown stops admission and drains active model work.
- Deployment. Each server runs one backend. Text generation is single-turn and returns one complete response. The protocol defaults to loopback and assumes a trusted network or secured tunnel for remote use.
Wire format, defaults, and delivery semantics
Benchmarks
On WSL2, single-client p95 for the RGB demo fell from 56.5 ms to 3.3 ms between 0.3 and 0.4. SmolLM2 delivered 98 output tokens/s with one client and two CPU threads. Run python scripts/benchmark.py from an installed source checkout to measure your machine.
Measured results and reproduction commands
Contribute
Built by Jamal Saeedi. Fork the repo to try a different model or improve the transport.
Star on GitHub · Fork · Report an issue · Contributing guide
Metadata
Release files for zmq-vision 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zmq_vision-0.4.0.tar.gz | 605.4 kB | With provenance | Details for zmq_vision-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zmq_vision-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for zmq_vision-0.4.0-py3-none-any.whl |
Total release size: 650.1 kB
Release files / zmq_vision-0.4.0.tar.gz
| Download URL | zmq_vision-0.4.0.tar.gz |
|---|---|
| Size | 605.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f715f8c50a06bbd2394750fb3cff1cdec4edbcbd20dded5df5760ae2708d3b64
|
|
BLAKE2b-256 checksum How to use checksums |
34a1c5fdc61ac76a090ab04456e14b5e3aca3ccd69d910b7132aa144cf84406b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logRelease files / zmq_vision-0.4.0-py3-none-any.whl
| Download URL | zmq_vision-0.4.0-py3-none-any.whl |
|---|---|
| Size | 44.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
99089969ca076baa0a97fc39e2fdd44c4e93c54ccdb3cabfea7dcc7ec8a59701
|
|
BLAKE2b-256 checksum How to use checksums |
bd7f6e04201978b48e307391c8b29528c76757b91532cb0a4e2d1595c7b66600
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logSecurity for zmq-vision 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for zmq_vision-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.