Code Monkey home page Code Monkey logo

easy-events's Introduction

easy-events

A library that help you to manage events

Getting started

  1. Installation
  2. Usages
  3. Code example
  4. Documentation

Installation

pip install easy-events

GitHub : Github

Usages

text

Code example

from easy_events import EasyEvents

# create an event or use it in a class
client = EasyEvents()


# create another event (can be sync or async)
# you can put as much parameters as you want
@client.add_event(aliases="test1")
def test(arg1, arg2, *, arg3):
	# data is the default parameter, it contain some basic informations that you can format as you want
	print(arg1, arg2, arg3)


# trigger the event
client.trigger(data=test1, parameters="arg1 arg2 arg3 arg4")
client.trigger("test1", "arg1 arg2 arg3 arg4")
client.trigger("test1", ["arg1", "arg2", "arg3", "arg4"])
client.trigger("test1", {"arg1": "arg1", "arg2": "arg2", "arg3": ["arg3", "arg4"]})

# dict way
client.trigger({"event": "test1", "parameters": {"arg1": "arg1", "arg2": "arg2", "arg3": ["arg3", "arg4"]}})

# dict way v2
client.trigger({"event": "test", "parameters": ["arg1", "arg2", "arg3", "arg4"]})

# dict way v3
client.trigger({"event": "test1", "parameters": "arg1 arg2 arg3 arg4"})

# list way
client.trigger(["test", "arg1", "arg2", "arg3", "arg4"])

# str way
client.trigger("test arg1 arg2 arg3 arg4")

# the result will be (for all cases):
# arg1 = arg1
# arg2 = arg2
# arg3 = [arg3, arg4]

This library also support type assignation

from easy_events import EasyEvents

client = EasyEvents()


@client.add_event()
def sum(X: int, Y: int):
	return X+Y


client.trigger("sum 5 10")
client.trigger(["sum", "5", 10])
# the result will be 15

Context support

from easy_events import EasyEvents


class CTX:
	def __init__(self, data: int = 0):
		self.data = data


client = EasyEvents(default_context=CTX)
# client = EasyEvents(default_context=CTX(0)) works as well

@client.add_event()
def context(ctx):
	print("ctx.data = ", ctx.data)


client.trigger("context", context=CTX(1))
client.trigger("context")

# this will print :
# "ctx.data = 1"
# "ctx.data = 0"

easy-events's People

Contributors

thephoenix78 avatar

Stargazers

 avatar  avatar  avatar Kwel999 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.