Skip to main content

Library for Event-Driven architecture using asyncio.

Project description

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

[Example]

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


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

If you're not sure about the file name format, learn more about wheel file names.

chronous-1.2.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file chronous-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: chronous-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for chronous-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4118cc0fa5f4a0f1baee23dfe6b39bf58cc6e217500d014a2ca66c3640462b88
MD5 89ae7b4a6706cb111f8679367279e8c0
BLAKE2b-256 4c983f207663193ec82c8c6c83b7dc2af7ecc6c4e7ba64e743807a4d67e31235

See more details on using hashes here.

Supported by

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