Skip to main content

A lightweight publish, subscribe library

Project description

Github can be found here

Setup

pip install yaps

CLI tools

To use the executables, ensure that yaps is installed which should put yaps-publish, yaps-subscribe and yaps-server available your path.

CLI Publish

yaps-publish --topic weather --message "Very cold today!"

CLI Subscribe

yaps-publish --topic weather

Python API

The client can be used either asynchronous or synchronous.

Publish Synchronous

from yaps.client import Client

client = Client('127.0.0.1', 8999)
client.publish(topic='weather', message='Very cold today!')

Subscribe Synchronous

from yaps.client import Client

client = Client('127.0.0.1', 8999)
client.subscribe(topic='weather',
                 data_received=lambda msg: print(f'New data: {msg}'))

Publish Asynchronous

import asyncio
from yaps.client import AsyncClient

client = AsyncClient('127.0.0.1', 8999)
asyncio.run(client.publish(topic='weather', message='Very cold today!'))

Subscribe Asynchronous

import asyncio
from yaps.client import AsyncClient

client = AsyncClient('127.0.0.1', 8999)
callback = lambda msg: print(f'New data: {msg}')
asyncio.run(client.subscribe(topic='test',
                             data_received=callback))

Server (Asynchronous only)

import asyncio
from yaps.server import Server

server = Server('127.0.0.1', 8999)
asyncio.run(server.start())

Logging

Logging is enabled by default and can be disabled by calling disable() on either a client or server. You can set the logging level by calling set_loglevel(string) with either a string, or an int directly from the logging module. Logging output is by default directed to both stdin and a log file, located at ~/.yaps on Unix systems (not 100% sure where this is located in Windows).

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

yaps-lib-0.0.1.tar.gz (15.9 kB view hashes)

Uploaded Source

Built Distribution

yaps_lib-0.0.1-py3-none-any.whl (24.3 kB view hashes)

Uploaded Python 3

Supported by

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