Event notifier with many subscribers support
Project description
event-notifier
Simple python notifier.
Contents
Background
This is event notifier (sometimes called emitter) allowing to notify one or many subscribers about something that just happen. Allows to use variable number of arguments. Is thread-safe.
Installation
pip install -U event-notifier
Usage
from EventNotifier import Notifier
class FileWatchDog():
def onOpen(self, fileName, openMode):
print(f"File {fileName} opened with {openMode} mode")
def onClose(self, fileName):
print(f"File {fileName} closed")
watchDog = FileWatchDog()
notifier = Notifier(["onCreate", "onOpen", "onModify", "onClose", "onDelete"])
notifier.addEventSubscriber("onOpen", watchDog.onOpen)
notifier.addEventSubscriber("onClose", watchDog.onClose)
notifier.fireEvent("onOpen", openMode="w+", fileName="test_file.txt") # order of named parameters is not important
notifier.fireEvent("onClose", fileName="test_file.txt")
Will produce:
$ python test.py
File test_file.txt opened with w+ mode
File test_file.txt closed
Constructor
Notifier(eventNames, logger=None)
Parameters
eventNames
-list
- mandatory, provides list of all supported events. Values provided here later can be used for raising eventslogger
-object
- optional, logger supporting standard logging methods (info, warning error, etc..), default:None
API Overview
fireEvent(eventName, *args, **kwargs)
removeSubscribersByEventName(eventName)
removeAllSubscribers()
addEventSubscriber(eventName, subscriber)
addEventSubscriber(subscriber)
Parameters
url
-string
- optional, Events API URL, default:http://localhost:4000
space
-string
- optional, space name, default:default
configurationUrl
-string
- optional, Configuration API URL. By default, it's the same asurl
but with4001
portconnectorUrl
-string
- optional, Connector API URL. By default, it's the same asurl
but with4002
portaccessKey
-string
- optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event Gateway
some Function Name here
Example
some other Function Name here
Utility to print the current configuration.
Example
#TBD
Tests
PyTest is used for tests. Python 2 is not supported.
Install PyTest
$ pip install pytest
Run tests
$ py.test test/*
License
License Copyright (C) 2020 Vitalij Gotovskij
event-notifier binaries and source code can be used according to the MIT License
Contribute
TBD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
event-notifier-0.1.7.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for event_notifier-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1dfe30b810b570fe122ef45e5a07e051cb6777dd48afad16a470e023caf584b |
|
MD5 | 67f7daad79ee0359c599bc698a2518de |
|
BLAKE2b-256 | 5569453676a4ca005b4b3ee2360ea6f54aca8be7cfe65902d6b80636776442a2 |