Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansq

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansq

Written with native Asyncio NSQ package

  • 0.3.0
  • PyPI
  • Socket score

Maintainers
2

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc