Library for Event-Driven architecture using asyncio.
Project description
=============== Chronous
|py_ver| |issues|
|pypi_ver| |pypi_license| |pypi_package| |pypi_status|
|discord|
Chronous is a asynchronous python library designed to make asynchronous event-driven architectures on discord.py
.. |py_ver| image:: https://img.shields.io/pypi/pyversions/chronous?label=Python%20Version&logo=python&logoColor=yellow :target: https://python.org .. |issues| image:: https://img.shields.io/github/issues/Lapis0875/Chronous?logo=github&logoColor=white :target: https://github.com/Lapis0875/Chronous/issues .. |pypi_ver| image:: https://img.shields.io/pypi/v/chronous?logo=pypi&logoColor=blue :target: https://pypi.org/project/chronous/ .. |pypi_license| image:: https://img.shields.io/pypi/l/chronous?logo=pypi&logoColor=blue :target: https://github.com/Lapis0875/Chronous/blob/master/LICENSE .. |pypi_package| image:: https://img.shields.io/pypi/format/chronous?label=package&logo=pypi :target: https://pypi.org/project/chronous/ .. |pypi_status| image:: https://img.shields.io/pypi/status/chronous?color=blue&logo=pypi&logoColor=blue :target: https://pypi.org/project/chronous/ .. |discord| image:: https://img.shields.io/discord/622434051365535745?color=blue&label=Discord&logo=Discord&logoColor=White :target: https://discord.gg/taVq6rw
[Example]
.. code-block:: python
import asyncio from typing import NoReturn import datetime from chronous.Architecture import BaseArchitecture from chronous.events import EventContext, Setup, Init, Start, Close
class SampleArchitecture(BaseArchitecture):
def __init__(self) -> None:
super(SampleArchitecture, self).__init__(name="sample")
# Registering events
self.register_event(event=Setup())
self.register_event(event=Init())
self.register_event(event=Start())
self.register_event(event=Close())
def run(self) -> None:
# Registering default lifecycle events
# Start process.
print("Starting process...")
asyncio.run(self.process())
async def process(self) -> NoReturn:
await self.dispatch("setup")
await self.dispatch("init")
print('='*20)
await self.dispatch("start", datetime.datetime.now())
index: int = 0
while index < 10:
print("Looping!")
index += 1
await self.dispatch("close")
print('='*20)
sample = SampleArchitecture()
Multiple listener sample
@sample.listen() async def setup(ec: EventContext): print("{e.name} phase - listener 1".format(e=ec.event))
@sample.listen() async def setup(ec: EventContext): print("{e.name} phase - listener 2".format(e=ec.event))
EventContext sample
@sample.listen() async def init(ec: EventContext): print("Initialization phase") print("Event : {e}".format(e=ec.event))
Additional arguments sample
@sample.listen() async def start(ec: EventContext, time: datetime): print("Starting process...") print("Starting at : {time}".format(time=time))
Exception sample
@sample.listen() async def close(ec: EventContext): print("Closing process...") print(f"Make an error : {1/0}")
sample.run()
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
Built Distribution
Hashes for chronous-2.0.0b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2a2b08f0dea98a7001bbca25262a93c000e9f6ad27ee4ba37d53aef665567c3 |
|
MD5 | cf5115d9f8426908bc3b8c3d37a9851e |
|
BLAKE2b-256 | ff99fa340ff1226b818d4dea7fa4d3447d35e226db1c68ed2c6ca7e107c94d3f |