lightning-fast, high-performance event handle framework
Project description
A lightweight event framework
Documentation: https://molto0504.github.io/tiny-listener
Source Code: https://github.com/molto0504/tiny-listener
Introduction
Tiny-listener is a lightweight and flexible event framework.
Requirements
Python 3.6+
Installation
$ pip install tiny-listener
Why use tiny-listener
- ✔ Pure Python.
- ✔ Lighting-fast, based on native coroutine.
- ✔ 100% test coverage.
Example
Create a file example.py
with:
from tiny_listener import Listener, Event
class App(Listener):
async def listen(self):
ctx = self.new_ctx()
ctx.fire("Say hi to Alice")
ctx.fire("Say hi to Bob")
ctx.fire("Say hi to Carol")
app = App()
@app.on_event("Say hi to {name}")
async def say_hi(event: Event):
print("Hi,", event.params["name"])
Run it:
$ tiny-listener example:app
>>> Hi, Alice
>>> Hi, Bob
>>> Hi, Carol
How it works
- Create your own Listener and listen something(e.g. port, queue ...):
from tiny_listener import Listener, Event
class App(Listener):
async def listen(self):
ctx = self.new_ctx()
ctx.fire("Say hi to Alice")
ctx.fire("Say hi to Bob")
ctx.fire("Say hi to Carol")
- Add event handler to your listener:
app = App()
@app.on_event("Say hi to {name}")
async def say_hi(event: Event):
print("Hi,", event.params["name"])
- Run listener with command:
$ tiny-listener example:app
- Tiny-listener will dispatch every event automatically:
>>> 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.13.tar.gz
(8.3 kB
view hashes)
Built Distribution
Close
Hashes for tiny_listener-0.0.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e019e89e434a2fbfc7fc28761e72f6aa8b9e430e921dba4d0e6a2f2c0e61ecae |
|
MD5 | 34571b58b56fc46ecfd04894fa4fd8af |
|
BLAKE2b-256 | 5299f1944fe6c5de51deab3bcd129d41c3e04aba9b622e1e8bf89eef925001f0 |