Skip to main content

lightning-fast, high-performance event handle framework

Project description

FastAPI

A lightweight event framework

Test Package version Supported Python versions


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

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

tiny_listener-0.0.12-py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page