PyVents is a powerful Python library for events
Project description
PyVents
PyVents is a powerful Python library for events.
Features
Installation
Using pip:
pip install pyvents
Using Poetry:
poetry add pyvents
Getting-Started
See examples for more.
Simple
from pyvents import Event
event = Event("myevent")
def subscriber():
print("Called subscriber")
def main():
event.subscribe(subscriber)
event.publish()
# Called subscriber
if __name__ == '__main__':
main()
Advanced
import threading
import asyncio
from pyvents import (
AsyncEvent,
Event,
EventChannel,
ThreadedEvent,
)
class MyEventChannel(EventChannel):
event = Event()
async_event = AsyncEvent()
threaded_event = ThreadedEvent()
@MyEventChannel.event.subscribe
def subscriber():
print("Called subscriber")
@MyEventChannel.async_event.subscribe
async def async_subscriber():
print("Called async_subscriber")
@MyEventChannel.threaded_event.subscribe
def threaded_subscriber():
print("Called threaded_subscriber")
print(f"Current thread: {threading.current_thread()}")
async def main():
MyEventChannel.event.publish()
# Called subscriber
await MyEventChannel.async_event.publish_async()
# Called async_subscriber
MyEventChannel.threaded_event.publish_threaded()
# Called threaded_subscriber
# Current thread: <Thread(Thread-1 (threaded_subscriber), started xxxx)>
if __name__ == "__main__":
asyncio.run(main())
Status
0.0.1
- RELEASED
License
PyVents is released under the MIT License. See the bundled LICENSE file for details.
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
pyvents-0.0.1.tar.gz
(4.1 kB
view hashes)