No project description provided
Project description
Eolic
Eolic is an event-driven library for Python that supports event emission, remote target handling, and listener registration with a simple and intuitive API.
The main purpose be an effective way to trigger hooks based on events and allow communication to another systems based on most common protocols.
Documentation
Read more about the usage with our Documentation / Examples
Installation
To install Eolic, clone this repository and run:
pip install eolic
Usage/Examples
from enum import Enum
from eolic import Eolic
# Defining all events on a enum (not required but it's a good pratice)
class GameEvents(Enum):
ON_PLAYER_JOIN = "ON_PLAYER_JOIN"
ON_PLAYER_ATTACK = "ON_PLAYER_ATTACK"
ON_MONSTER_DEFEATED = "ON_MONSTER_DEFEATED"
ON_GAME_OVER = "ON_GAME_OVER"
# Instancing Eventypy class defining a webhook as remote_target for "ON_MONSTER_DEFEATED" event
handler = Eolic(remote_targets=[
{
"type": "url",
"address": "https://mysite.site/api/game/hooks",
"headers": {"X-Game-Event":"RPGSecretKey"},
"events": [GameEvents.ON_MONSTER_DEFEATED]
}
])
# Defining hooks that will be executed locally
@game_event_handler.on(GameEvents.ON_PLAYER_JOIN)
def handle_player_join(player_name):
print(f"{player_name} has joined the game!")
@game_event_handler.on(GameEvents.ON_PLAYER_ATTACK)
def handle_player_attack(player_name, monster_name, damage):
print(f"{player_name} attacked {monster_name} for {damage} damage!")
@game_event_handler.on(GameEvents.ON_MONSTER_DEFEATED)
def handle_monster_defeated(player_name, monster_name):
print(f"{player_name} has defeated {monster_name}!")
@game_event_handler.on(GameEvents.ON_GAME_OVER)
def handle_game_over():
print("Game Over! Thanks for playing.")
# Emitting player join event
game_event_handler.emit(GameEvents.ON_PLAYER_JOIN, "Archer")
# Emitting player attack event
game_event_handler.emit(GameEvents.ON_PLAYER_ATTACK, "Archer", "Goblin", 30)
# Emitting monster defeated event
game_event_handler.emit(GameEvents.ON_MONSTER_DEFEATED, "Archer", "Goblin")
# Emitting game over event
game_event_handler.emit(GameEvents.ON_GAME_OVER)
Roadmap
- Implement integration for celery backend (RabbitMQ, Redis)
- Implement Direct RabbitMQ
- Allow Emit Async and Sync options
License
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
eolic-0.1.0-py3-none-any.whl
(7.0 kB
view details)
File details
Details for the file eolic-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: eolic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.9.16 Linux/6.2.0-39-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cc5c04253924686c95676bdc81985ad677823ebe7c02ff39becca2b96e37565 |
|
MD5 | 92de578c7052ed958fa42556a972f9fc |
|
BLAKE2b-256 | 97b1638398b275aee9cbfb534bd8c44147505e416ae651245c1efd02381fc313 |