Metadata-Version: 2.1
Name: yaps-lib
Version: 0.0.1
Summary: A lightweight publish, subscribe library
Home-page: https://github.com/victorhook/yaps
Author: Victor Krook
Author-email: victorkrook96@gmail.com
License: UNKNOWN
Project-URL: Bug Tracker, https://github.com/victorhook/yaps/issues
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown

Github can be found [here](https://github.com/victorhook/yaps)

## 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).



