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):
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):
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):
self.fire("Say hi to Alice")
self.fire("Say hi to Bob")
self.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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for tiny_listener-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32795c4e9bf75094b3947252d95f9aca50738034637c9d4c2b9e88b67a9fb644 |
|
MD5 | 3216e2a3e442b739085d9fb19bb02834 |
|
BLAKE2b-256 | 33b4b422ee0de062029141bf0a98f70a0556048d9b48489b2017d91e999dcb86 |