Skip to main content

ansq - Async NSQ

PyPI version Tests Coverage PyPI - Python Version

Written with native Asyncio NSQ package

Installation

python -m pip install ansq

Overview

  • 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

Features

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

Usage

Consumer

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(
        topic="example_topic",
        channel="example_channel",
    )

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

    await reader.close()


if __name__ == "__main__":
    asyncio.run(main())

Producer

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

import asyncio

import ansq


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


if __name__ == "__main__":
    asyncio.run(main())

Contributing

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.

pytest

Release files for ansq 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansq 0.3.0
File Size Uploaded
ansq-0.3.0.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ansq 0.3.0
File Interpreter ABI Platform
ansq-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.5 kB

Release files / ansq-0.3.0.tar.gz

Download URL ansq-0.3.0.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ec35ad42eed8f100ac0f14067b1bda43938b68de22bc0f22ec990e05036dabfb
BLAKE2b-256 checksum
How to use checksums
418992a1027653401655a947b755ae17e857623d62305ef14e75b71894a217cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / ansq-0.3.0-py3-none-any.whl

Download URL ansq-0.3.0-py3-none-any.whl
Size 28.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40659c6b25aef0e03608aadf6b4c78f235273afafd8b002bfde8f0e1d64ade36
BLAKE2b-256 checksum
How to use checksums
258083aca9e509ac0c34c19adae8d7cce36db89d7f0aba7a3d070ee4c05b6da7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page