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.*+
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.14.tar.gz
(9.8 kB
view hashes)
Built Distribution
Close
Hashes for tiny_listener-0.0.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a881f94134f971c7df3f6cbcd14d85ff5b50ab19fc7079cb5fda561a88928fb |
|
MD5 | e02541fab037714364c356fbe7877154 |
|
BLAKE2b-256 | 909b783cafbc0e5b4ca09fffd44d2c7e44656fad7c57c38d6426e1496eb8d6b4 |