Skip to main content

Written with native Asyncio NSQ package

Project description

ansq - Async NSQ

PyPI version Tests Coverage PyPI - Python Version

Written with native Asyncio NSQ package


python -m pip install ansq


  • Reader — high-level class for building consumers with nsqlookupd support
  • Writer — high-level producer class supporting async publishing of messages to nsqd over the TCP protocol
  • NSQConnection — low-level class representing a TCP connection to nsqd:
    • full TCP wrapper
    • one connection for sub and pub
    • self-healing: when the connection is lost, reconnects, sends identify and auth commands, subscribes to previous topic/channel


  • SUB
  • PUB
  • Discovery
  • Backoff
  • TLS
  • Deflate
  • Snappy
  • Sampling
  • AUTH



A simple consumer reads messages from "example_topic" and prints them to stdout.

import asyncio

import ansq

async def main():
    reader = await ansq.create_reader(

    async for message in reader.messages():
        print(f"Message: {message.body}")
        await message.fin()

    await reader.close()

if __name__ == "__main__":


A simple producer sends a "Hello, world!" message to "example_topic".

import asyncio

import ansq

async def main():
    writer = await ansq.create_writer()
        message="Hello, world!",
    await writer.close()

if __name__ == "__main__":


Create and activate a development virtual environment.

python -m venv venv
source venv/bin/activate

Install ansq in editable mode and its testing dependencies.

python -m pip install -e .[testing]

Run tests.


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

ansq-0.2.0.tar.gz (23.8 kB view hashes)

Uploaded source

Built Distribution

ansq-0.2.0-py3-none-any.whl (28.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page