lightning-fast, high-performance event handle framework
Project description
Tiny-listener
Tiny-listener is a lightweight event framework with Python 3.6+
Requirements
Python 3.6+
Installation
$ pip install tiny-listener
Why use tiny-listener:
- ✔ Pure Python, tiny install pack
- ✔ Lighting-fast, based on native coroutine
- ✔ Easy to use
How it works:
- Write your event handler, such as:
@app.on_event("emergency")
def plan_B():
# do something
...
@app.on_event()
def plan_A():
# do something
...
- Keep listening (e.g. port, quene ...) until something happen, such as:
async def listen(self):
while True:
msg: str = await queue.get() # msg may be "emergency" or some other status
self.fire(msg) # fire event
-
Tiny-listener will dispatch event automatically:
- Normally, when listener receive a
msg
,plan_A
will be called by default. - If
msg
isemergency
thenplan_B
will be called instead ofplan_A
.
- Normally, when listener receive a
Usage
example.py
from tiny_listener import Listener, Event
class App(Listener):
async def listen(self):
"""listen event"""
self.fire("Say hi to Alice")
self.fire("Say hi to Bob")
self.fire("Say hi to Carol")
app = App()
@app.on_event("Say hi to {name}")
async def say_hi(event: Event):
"""handle event"""
print("Hi,", event.params["name"])
Run application using tiny-listener command:
$ tiny-listener example:app
>>> Hi, Alice
>>> Hi, Bob
>>> Hi, Carol
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
tiny-listener-0.0.10.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for tiny_listener-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c56711ea99ccb67abfb9e71cf952dafdd4c35bacedd768ccad2002494b58ee6 |
|
MD5 | cf32cc04b572b93fa28a67f718e6c9e7 |
|
BLAKE2b-256 | bc6dbd977553cd45f520f1881ff1ef2689eb01b8e60fcedd4e2d6d06491c0052 |